怎样在C中一行一行读取文件的内容?急

如题所述

fgets()函数遇到回车返回,所以适合读一行
函数名: fgets
功 能: 从流中读取一字符串
用 法: char *fgets(char *string, int n, FILE *stream);程序例:
#include <string.h
#include <stdio.h
int main(void){FILE *stream;
char string[] = "This is a test";
char msg[20];
/* open a file for update */
stream = fopen("DUMMY.FIL", "w+");
/* write a string into the file */
fwrite(string, strlen(string), 1, stream);
/* seek to the start of the file */
fseek(stream, 0, SEEK_SET);
/* read a string from the file */
fgets(msg, strlen(string)+1, stream);
/* display the string */
温馨提示:答案为网友推荐,仅供参考
相似回答