6-1 读文章(*)

请编写函数,从文件中读出文章,将其输出到屏幕上。

函数原型

void ReadArticle(FILE *f);

说明:参数 f 为文件指针。函数读出 f 所指示文件中的文章,将其输出到屏幕上。

裁判程序

#include <stdio.h>
#include <stdlib.h>

void ReadArticle(FILE *f);

int main()
{
    FILE *f;
    f = fopen("Article.txt", "r");
    if (!f)
    {
        puts("文件无法打开!");
        exit(1);
    }

    ReadArticle(f);

    if (fclose(f))
    {
        puts("文件无法关闭!");
        exit(1);
    }
    return 0;
}

/* 你提交的代码将被嵌在这里 */

打开 Windows 的记事本软件,复制下面的文字内容,保存文件并命名为“Article.txt”。

Article.txt

A Cure for a Headache

One day a man went into a chemist's shop and said, "Have you anything to cure a
headache?"
The chemist took a bottle from a shelf,  held it under the gentleman's nose and
took out the cork.  The smell was so strong that tears came into the man's eyes
and ran down his cheeks.
"What did you do that for?"  he said angrily,  as soon as he could get back his
breath.
"But that medicine has cured your headache, hasn't it?" said the chemist.
"You fool," said the man, "It's my wife that has the headache, not me!"

输入样例

()

输出样例

A Cure for a Headache

One day a man went into a chemist's shop and said, "Have you anything to cure a
headache?"
The chemist took a bottle from a shelf,  held it under the gentleman's nose and
took out the cork.  The smell was so strong that tears came into the man's eyes
and ran down his cheeks.
"What did you do that for?"  he said angrily,  as soon as he could get back his
breath.
"But that medicine has cured your headache, hasn't it?" said the chemist.
"You fool," said the man, "It's my wife that has the headache, not me!"

示例;

void ReadArticle(FILE *f)
{
	char  ch;
    ch=fgetc(f);
	while (ch != -1)
	{
		printf("%c",ch);
        ch=fgetc(f);
	}
}
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

懒回顾,半缘君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值