【C语言编程】统计一个文本文件的行数

来源:互联网 发布:apache 域名泛解析 编辑:程序博客网 时间:2024/05/17 04:26
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<windows.h>int main(){char f[10]={0},ch;int cap=0;//行数FILE *fp;gets(f);if((fp=fopen(f,"r"))==NULL){printf("Can not open this file.\n");exit(0);}while(!feof(fp)){if((ch=getc(fp))!=EOF){if((ch=getc(fp))=='\n')cap++;}}cap++;printf("cap=%d\n",cap);fclose(fp);system("pause");}

                                             
0 0