Create a File and Display its Contents
Here you will learn and get source code of c program to create a file and display its contents using files in c. This is the basic example of file handling in c programming.
C program to Create a File and Display its Contents
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<stdio.h> main() { FILE *fp; char c; printf("\n\nEnter Data to input in file(for end press ctrl+z) : \n"); //Create a fie fp=fopen("coderevise.txt","w"); // Write data to file while((c=getchar( ))!=EOF) putc(c,fp); fclose(fp); // print data from file printf("\n\nPrint Data form file \n"); fp=fopen("coderevise.txt","r"); while((c=getc(fp))!=EOF) printf("%c",c); fclose(fp); } |
Output
Check out our other C programming Examples