#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
//判断文件个数是否为2
if(argc != 2)
{
printf("input file error\n");
printf("usage:./a.out fileName\n");
return -1;
}
//定义文件指针
FILE *fp;
if ((fp = fopen(argv[1],"r")) == NULL)
{
perror("fopen error");
return -1;
}
int count = 0;
char s[2000];
while (fgets(s,sizeof(s),fp) != NULL)
{
count++;
}
fclose(fp);
printf("count = %d\n",count);
return 0;
}
6-20-home
最新推荐文章于 2024-05-19 21:23:41 发布