C Program to read the content of file using fgets
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h> #include <stdlib.h> void main() { FILE *fp; char str[80], fname[50]; printf("Enter the file name:"); scanf("%s",fname); if ((fp= fopen(fname, "r")) == NULL) { printf("cannot open file"); exit(1); } while(!feof(fp)) { fgets(str,79,fp); printf("%s",str); } fclose(fp); } |
Output :
1 2 | Enter the file name : input.txt Hello, How are you ? |