Get a string from a stream: how to use fgets
#include <stdio.h>
int main()
{
FILE *file;
char string [100];
file = fopen ("my.txt" , "r");
if (file == NULL)
perror ("Error reading file");
else {
fgets (string , 100 , file);
puts (string);
fclose (file);
}
return 0;
}
Related examples in the same category