Page

Perform File Operation in C language

#include<stdio.h>  
#include<conio.h>
 void main()  
 {  
 FILE *fi,*fo;  
 char c;  
 char fin[125],fout[125],indata[500];  
 clrscr();  
 puts("             File Input&Copy             " );  
 puts("Input Data \n");  
 gets(indata);  
 puts("\nSave File as: ");  
 gets(fout);  
 fo=fopen(fout,"w");  
 fi=fopen(fout,"r");  
 fprintf(fo,indata);  
 puts("\nSave copy as: ");  
 gets(fout);  
 fo=fopen(fout,"w");  
 while(1)  
 {  
 c=getc(fi);  
 if (c==EOF)  
 break;  
 putc(c,fo);  
 }  
 puts("File copied successfully");  
 puts("\n");  
 printf("Reading from file:%s \n \n ",fout);  
 fprintf(fo,indata);  
 puts(indata);  
 getch();  
 }  

No comments:

Post a Comment