| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 429 人关注过本帖
标题:小菜求助如何读完后如何停止
取消只看楼主 加入收藏
莫桑比克
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
快速回复:小菜求助如何读完后如何停止
数据加载中...
 
   



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

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