fgetc获取文件的行号(文件有多少行,使用函数读取换行个数)
#include <myhead.h>
int main(int argc, const char *argv[])
{
FILE *fp;
fp=fopen("./1.text","r");
if(fp==NULL)
{
perror("fopen");
return -1;
}
char ch;
int count=0;
while((ch=fgetc(fp))!=EOF)
{
if(ch=='\n')
{
count++;
}
}
printf("%d\n",count);
return 0;
}
1.text
xmind