![Write a C Program for Text File Handling Text File Handling , Timus Rak , Sumit Kar](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgEEuiVQujzDYGlv1PMDzDKYb5ozvCbIjo_Mt3FOu_A8h6GVex9UkCglRQEuc0wTKxbm_OgzCSMsAl0xTsTrdYwnZVmL3fFis99MAlE7B7SZTE3u-l8-Yoy14a7zhjLCMXS_y2grkLeaBz/s1600/c-programming-tutorial.jpg)
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp; // declaration of file pointer
char c;
clrscr();
fp=fopen("fileinC.txt","w"); // opening a new file in write mode
if(fp==NULL) // checking for file opening error
{ printf("\n\nFile opening error!");
getch();
exit(0);
}
printf("\nEnter the text for file?\n[Press Ctrl+Z to terminate]\n");
while((c=getchar())!= EOF) //read character from keyboard
putc(c,fp); //put the entered character into file
fclose(fp); //close the file
fp=fopen("fileinC.txt","r"); //reopen the file in read mode
while((c=getc(fp))!= EOF) //reading single character from file until EOF found
printf("%c",c);
fclose(fp); //finally closing the file
getch();
}
0 Comments