Mega Code Archive

 
Categories / C / Code Snippets
 

Get a string from a stream how to use fgets

#include <stdio.h> int main() { FILE *file; char string [120]; file = fopen ("myfile.txt" , "r"); if (file == NULL) perror ("Error reading file"); else { fgets (string , 120 , file); puts (string); fclose (file); } return 0; }