C language – fgets

อ่านข้อมูลจากไฟล์ทีละบรรทัด

[code lang=”c”]
/* fgets exmaple */

#include

#define myfile "control"

int main() {
FILE * fp;

fp = fopen(myfile, "r");
if (fp == NULL)
perror("Error opening file");
else {
char mystring[100];
while (fgets(mystring, sizeof(mystring), fp)) {
printf(mystring);
}
fclose(fp);
}
return 0;
}
[/code]

ที่มา: cplusplus