当前位置:网站首页>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();
}
}
边栏推荐
- AXI协议基础知识
- Classic reading of multi task learning: MMOE model
- Characteristics of interfaces & comparison between interfaces and abstract classes
- mysql 大表的拆分方式
- Authing 背后的计算哲学
- Authing biweekly news: authing forum launched (4.25-5.8)
- Axi protocol Basics
- sql server中移除key lookup书签查找
- Science popularization genius on the left, madman on the right
- 使用exe4j 将.jar文件打包为.exe文件
猜你喜欢

The use of histogram function in MATLAB

通过Xshell连接有跳板机/堡垒机的服务器

Center detection of circular marking points for opencv camera calibration

Solr (I) installation and permission control of Solr

定制 or 订阅?未来中国 SaaS 行业发展趋势是什么?

sql server中关于FORCESCAN的使用以及注意项

你还不懂线程池的设计及原理吗?掰开揉碎了教你设计线程池

Format eslint automatique lorsque vscode enregistre le Code

Authing biweekly news: online application market (5.10-5.22)

How to become an optimist organization?
随机推荐
Analyze which should be tested in PMP and ACP with actual cases? Which is more useful?
04_特征工程—特征选择
LeetCode-384. Scramble array
Authing biweekly news: online application market (5.10-5.22)
Environment configuration and pymysql installation
Set object mapping + scene 6-face mapping + create space in threejs
DFS and BFS notes (I) breadth first search based on C language
Haas, which integrates relevant technologies of Alibaba cloud, Dharma Institute and pingtouge, has officially announced the book
TypeScript学习笔记(二)
C语言:使用.h和.c文件遇到的问题总结
vscode配置eslint自动格式化报错“The setting is deprecated. Use editor.codeActionsOnSave instead with a source“
LeetCode-1005. Maximized array sum after K negations
搜狐全員遭詐騙,暴露哪些問題?
Semaphore PV operation of process interaction and its code implementation
Qlineedit set input mask
TestPattern error
Authing 双周动态:Authing 论坛上线(4.25-5.8)
Char array parsing
小白在同花顺上直接办理账户是安全的吗?
threejs中设置物体的贴图+场景的6面贴图 +创建空间