函数原型:
#include <stdio.h>
char * fgets( char *str, int num, FILE *stream );
参数:
num: 最多读取num-1个字符,或者遇到文件结束符EOF为止(即“文件读完了”)返回值; 读取失败时, 返回NULL,读取成功时,返回str
#include <stdio.h>
int main(void) {
FILE *file1;
char tmp[64];
char c;
file1 = fopen("test.c", "r");
while (fgets(tmp, sizeof(tmp), file1) != NULL) {
printf("%s", tmp);
}
fclose(file1);
return 0;
}