简易C语言——读取一个文件内容
#include <stdio.h>
#include <stdlib.h>
#define FILE_PATH "/home/sns/lsusb" /*文件路径*/
int main(void)
{
char buff[512];
char string1[50];
char string2[50];
FILE *pFile = fopen(FILE_PATH, "r");
if (pFile == NULL) {
return -1;
}
while (!feof(pFile)) { /*读取文档,直到文件结束*/
fgets(buff, sizeof(buff), pFile);
printf(" %s \n", buff);
}
fclose(pFile);
return EXIT_SUCCESS;
}