文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>putchar输出错误

putchar输出错误

时间:2010-08-24  来源:huazaicola

#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
        int get_char = 0;
        char s[20] = "i love linux!";
        FILE *fd;
        if(argc < 2)
        { printf("please input pathname!\n");
                exit(1);
        }
        if((fd = fopen(argv[1],"w+")) == NULL)
        {
                printf("open failure!\n");
                exit(1);
        }
        while(get_char != EOF)
        {
              putchar(get_char);      // 1

              get_char = fgetc(fd);// 2  将1 和 2 交换会出现一个小错误
                
        }
        fclose(fd);
        return 0;
}


错误分析: 当1和2交换后,先获取字符,后输出,当到达文件尾时,get_chat=EOF,此时输出错误。

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载