#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
char *linebuf;
size_t linesize;
FILE *fp;
int count;
if(argc < 2)
{
fprintf(stderr,"Usage.....\n");
exit(1);
}
//从终端命令行参数得去文件
fp = fopen(argv[1], "r");
if(fp == NULL)
{
perror("fopen_argv[1]");
exit(1);
}
linebuf = NULL;
linesize = 0;
while(1)
{
//利用getlien读取文件每一行数据
if(getline(&linebuf, &linesize, fp) < 0)
break;
printf("%s\n",linebuf);
printf("%d\n",strlen(linebuf));
//printf("%d\n",linesize);
}
fclose(fp);
exit(0);
}
06-13
4904
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-26
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交