zoukankan      html  css  js  c++  java
  • 6-2 读文章(*)

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

    函数原型

    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!=EOF)
        {
            printf("%c",ch);    //输出,不断重复
            ch=fgetc(f);//fgetc读取一个字节后,光标位置后移一个字节
        }
    }
     
  • 相关阅读:
    .NET 中验证控件的使用
    Input(file) 控件的简单使用!
    dropdownlist 、listbox 与 panel的使用
    Applicatin、 server、 session 、cookies对象的简单使用方法
    三天晚上看了24集 央视版《神雕侠侣》 还不错
    推荐一本 asp.net(c#)学习的好书
    .net 中广告控件 AdRotator 的使用(xml)
    Asp.net 1.0 升级至 ASP.NET 2.0十个问题总结
    多线程操作 同一个textbox. yi
    博客开张第一贴!谢谢!大伙多多关照!谢谢. yi
  • 原文地址:https://www.cnblogs.com/rebloom000/p/12984807.html
Copyright © 2011-2022 走看看