标题:小菜求助如何读完后如何停止
取消只看楼主
莫桑比克
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-8-2
结帖率:20%
已结贴  问题点数:20 回复次数:1 
小菜求助如何读完后如何停止

求助以下源码如何读完后如何停止

#include <stdio.h>
int main()
{
    FILE *in;
    int i;
    int *a;
    in=fopen("stdin.c","r");
   
    for(;i!=EOF; i++)
        {     
    fscanf(in,"%c",&a);
        printf("%c\n",a);
        }
    fclose(in);
    return 0;
}

读的系以下文件
#include <string.h>

#include <stdio.h>

 

int main(void)

{

FILE *stream;

char string[] = "This is a test";

char msg[20];

 

/* open a file for update */

stream = fopen("DUMMY.FIL", "w+");

 

/* write a string into the file */

fwrite(string, strlen(string), 1, stream);

 

/* seek to the start of the file */

fseek(stream, 0, SEEK_SET);

 

/* read a string from the file */

fgets(msg, strlen(string)+1, stream);

 

/* display the string */

printf("%s", msg);

 

fclose(stream);

return 0;

}

[ 本帖最后由 莫桑比克 于 2011-8-2 22:14 编辑 ]
搜索更多相关主题的帖子: include return stream update write 
2011-08-02 22:13
莫桑比克
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-8-2
得分:0 
谢谢了。
2011-08-03 11:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-346649-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.071295 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved