当前位置:网站首页>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();
}
}
边栏推荐
- 通过Xshell连接有跳板机/堡垒机的服务器
- Authing CEO 谢扬入选福布斯 2021 年 30 Under 30 亚洲榜单
- Is the second-class cost engineer worth the exam? What is the development prospect?
- GemBox. Bundle 43.0 Crack
- The use of histogram function in MATLAB
- sql server中移除key lookup书签查找
- Connect the server with springboard / fortress through xshell
- TypeScipt基础
- 定制 or 订阅?未来中国 SaaS 行业发展趋势是什么?
- LeetCode-859. 亲密字符串
猜你喜欢

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

CLP information -5 keywords to see the development trend of the financial industry in 2022

From a "trendsetter" to a "wind chaser", can master Kang still lead the market?

GemBox. Bundle 43.0 Crack

Vscode configures eslint to automatically format an error "auto fix is enabled by default. use the single string form“

【线上问题】Timeout waiting for connection from pool 问题排查

10 times faster than 5g. Are you ready for 10 Gigabit communication?

Bentley uses authing to quickly integrate application system and identity

Authoring share | understanding saml2 protocol

What subclasses inherit, polymorphism, and upward transformation
随机推荐
Science popularization genius on the left, madman on the right
LeetCode-1005. K 次取反后最大化的数组和
Bentley uses authing to quickly integrate application system and identity
A simple understanding of closures
Association relationship
Authing biweekly news: online application market (5.10-5.22)
CentOS7服务器配置(四)---安装redis
信息安全数学基础 Chapter 3——有限域(一)
说说集合的面试题
CS0006 C# 未能找到元数据文件“C:\Users\...问题
ffmpeg CBR精准码流控制三个步骤
ffmpeg硬编解码 Inter QSV
Haas, which integrates relevant technologies of Alibaba cloud, Dharma Institute and pingtouge, has officially announced the book
Activity | authing's first channel cooperation activity came to a successful conclusion
Axi protocol Basics
Oracle analysis function over and MySQL achieve similar effects
Typescript learning notes (II)
Pychart tips - how to set up a background picture
从制造到“智造”,探索制造企业破局之道
Xie Yang, CEO of authing, was selected into Forbes' 30 under 30 Asia list in 2021