feof 的理解

来源:互联网 发布:局域网内网监控软件 编辑:程序博客网 时间:2024/06/03 05:47

例:写一个函数统计文件中字符的个数

















int getFileSize(char *path, int *len)

{
FILE*fp = fopen(path, "r");
if (fp==NULL)
{
perror("open_err");
return -1;
}
*len = 0;
char ch;
       //unsigned char ch;

//使用while(1)型的判断会更好的反映程序内部运行情况

//while(1)  

//{

// if(..)  break;

// if(..)continue;

//}

while(1) 
{
ch = fgetc(fp);
if (ch >= 0 && ch < 128)
{
if (ch == '\n')
{
continue;
}
(*len)++;
continue;
}
else
{
break;
}
}
return 0;
}

0 0
原创粉丝点击