Write a C Program for Text File Handling



Text File Handling , Timus Rak , Sumit Kar



#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();

}

Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C