Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7510
  • 博文数量: 14
  • 博客积分: 250
  • 博客等级: 二等列兵
  • 技术积分: 95
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-13 01:08
文章分类
文章存档

2011年(14)

我的朋友
最近访客

分类: IT职场

2011-01-13 04:13:34

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int main(int argc, char **argv)
  5. {
  6.         FILE *fp;
  7.         static char *linebuf = NULL;
  8.         static size_t linesize = 0;
  9.         if(argc < 2)
  10.         {
  11.                 fprintf(stderr, "Usage...\n");
  12.                 exit(1);
  13.         }
  14.         fp = fopen(argv[1], "r");
  15.         if((fp == NULL))
  16.         {
  17.                 perror("fopen() error");
  18.                 exit(1);
  19.         }
  20.         while(1)
  21.         {
  22.                 if(getline(&linebuf, &linesize, fp) < 0)
  23.                 {
  24.                         break;
  25.                 }
  26.                 printf("%d\n", strlen(linebuf));
  27.         }
  28.         fclose(fp);
  29.         return 0;
  30. }
  31. ~
  32. ~
阅读(268) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~