打开文件 fopen("需要打开的路径")
然后使用fgets函数读取行
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LINE 1024
int main()
{
     char buf[MAX_LINE];  /*缓冲区*/
     FILE *fp;            /*文件指针*/
     int len;             /*行字符个数*/
     if((fp = fopen("test.txt","r")) == NULL)
     {
          perror("fail to read");
          exit (1) ;
     }
     while(fgets(buf,MAX_LINE,fp) != NULL)
     {
        len = strlen(buf);
        buf[len-1] = '\0';  /*去掉换行符*/
        printf("%s %d \n",buf,len - 1);
      }
  return 0;
}

参考http://zhidao.baidu.com/link?url=v05snVw-rKwoInpurhiYP8d9ACTJHjX4yX8-2eIX9RZbMrR-3yXjrj5_aaPwMkhDxheZoSJj3Gf0IDg29vj95q

相关文章:

  • 2021-12-18
  • 2021-07-28
  • 2021-06-22
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2021-06-05
  • 2021-12-18
猜你喜欢
  • 2022-12-23
  • 2022-02-07
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2022-01-31
  • 2021-11-28
相关资源
相似解决方案