当前位置:网站首页>6-2 写文章(*)
6-2 写文章(*)
2022-06-11 17:17:00 【西红柿_码农】
6-2 写文章(*)
分数 10
全屏浏览题目
切换布局
作者 李祥
单位 湖北经济学院
请编写函数,从键盘输入一篇文章,将其写入到文件中。
函数原型
void WriteArticle(FILE *f);说明:参数 f 为文件指针。函数从键盘输入一篇文章(由若干行文字组成,以 Ctrl+Z 结束),将其写入 f 所指示的文件中。
裁判程序
#include <stdio.h>
#include <stdlib.h>
void WriteArticle(FILE *f);
int main()
{
FILE *f;
f = fopen("Article.txt", "w");
if (!f)
{
puts("文件无法打开!");
exit(1);
}
WriteArticle(f);
if (fclose(f))
{
puts("文件无法关闭!");
exit(1);
}
puts("文件保存成功!");
return 0;
}
输入样例
Poor Old Gentleman
An old gentleman was walking slowly along a street one day when he saw a little
boy who was trying to reach a doorbell which was too high for him. He was a
kind-hearted old man, so he stopped and said, "I will ring the bell for you,"
and then he pulled the bell so hard that it could be heard all over the house.
The little boy looked up at him and said, "Now we will run away. Come on." And
before the old gentleman knew what was happening, the naughty boy had run round
the corner of the street, leaving the man to explain to the angry owner of the
house why he had rung the bell.
提示:最后一行输入完以后打回车键,在下一行的开头按下 Ctrl + Z (屏幕显示为 ^Z),然后再打回车键结束输入。
输出样例
文件保存成功!
打开“Article.txt”文件,查看文件内容。
Article.txt
Poor Old Gentleman
An old gentleman was walking slowly along a street one day when he saw a little
boy who was trying to reach a doorbell which was too high for him. He was a
kind-hearted old man, so he stopped and said, "I will ring the bell for you,"
and then he pulled the bell so hard that it could be heard all over the house.
The little boy looked up at him and said, "Now we will run away. Come on." And
before the old gentleman knew what was happening, the naughty boy had run round
the corner of the street, leaving the man to explain to the angry owner of the
house why he had rung the bell.void WriteArticle(FILE *f){
char data;
data=getchar();
while(data!=EOF){
fputc(data,f);
data=getchar();
}
}
边栏推荐
- 论文阅读 dyngraph2vec: Capturing Network Dynamics using Dynamic Graph Representation Learning
- sql server中关于FORCESCAN的使用以及注意项
- Vscode configures eslint to automatically format with an error "the setting is deprecated. use editor.codeactionsonsave instead with a source“
- 从制造到“智造”,探索制造企业破局之道
- Song of the sea in 5g Era
- CLP information -5 keywords to see the development trend of the financial industry in 2022
- Docker安装mysql5.7(开启binlog功能、修改字符)
- (validation file) validatejarfile report errors
- leetcode--数组
- Vscode automatic eslint formatting when saving code
猜你喜欢

DFS和BFS笔记(一)基于C语言的广度优先搜索

Classic reading of multi task learning: MMOE model

Custom or subscription? What is the future development trend of China's SaaS industry?

GemBox. Bundle 43.0 Crack

搜狐全員遭詐騙,暴露哪些問題?

论文阅读 dyngraph2vec: Capturing Network Dynamics using Dynamic Graph Representation Learning

Chip mass production, oppo entering a new era?
![[Clickhouse column] create a new library, user and role](/img/e5/d11493a37e25b7dde6cc43b3828749.png)
[Clickhouse column] create a new library, user and role

What subclasses inherit, polymorphism, and upward transformation

How to simplify a lot of if... Elif... Else code?
随机推荐
Environment configuration and pymysql installation
信息安全数学基础 Chapter 3——有限域(一)
Biden ordered to enforce the zero trust structure
Authing 双周动态:Authing 论坛上线(4.25-5.8)
vscode配置eslint自动格式化报错“The setting is deprecated. Use editor.codeActionsOnSave instead with a source“
Leetcode 450. Deleting a node in a binary search tree
MATLAB中histogram函数的使用
Splitting method of MySQL large tables
Connect the server with springboard / fortress through xshell
子类继承了什么、多态、 向上转型
ffmpeg硬编解码 Inter QSV
Science popularization genius on the left, madman on the right
Real time myth -- real-time RTOS multitask performance analysis
CLP information -5 keywords to see the development trend of the financial industry in 2022
Authing 双周动态:应用市场上线(5 .10 —5 .22 )
从制造到“智造”,探索制造企业破局之道
闭包的简单理解
啟牛商學院給的證券賬戶是安全的嗎?開戶收費嗎
自动化测试-Selenium
LeetCode——42. Connected to rainwater (double pointer)