#include<myhead.h>
int main(int argc, const char *argv[])
{
FILE *fp1 = fopen("./1.txt","r");
if(fp1 == NULL)
{
perror("fopen");
return -1;
}
char buff[20] = "";
int count = 0;
int i =0;
while(fgets(buff,sizeof(buff),fp1)!=NULL)
{
if(buff[i]=='\n')
{
i++;
}
else
{
count++;
i = 0;
}
printf("%s",buff);
}
printf("有%d行\n",count);
fclose(fp1);
fp1 =NULL;
return 0;
}
作业 fgets获取文件的行号
于 2024-08-20 20:13:50 首次发布