Virajsinh

FileHandling_1

Nov 16th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. void main()
  5. {
  6.     FILE *fp1, *fp2;
  7.     char FileName[20], FileName2[20], str[500];
  8.     clrscr();
  9.  
  10.     printf("\n Enter First File Name : ");
  11.     gets(FileName);
  12.     fflush(stdin);
  13.     printf("\n Enter Second File Name : ");
  14.     fflush(stdin);
  15.     gets(FileName2);
  16.  
  17.     if((fp1=fopen(FileName,"r"))==0)
  18.     {
  19.         //First Creat Text File
  20.         printf("\n Error First File");
  21.         exit(1);
  22.     }
  23.  
  24.     if((fp2=fopen(FileName2,"w"))==0)
  25.     {
  26.         //Create A New File
  27.         printf("\n Error Second File");
  28.         exit(1);
  29.     }
  30.  
  31.     while((fgets(str,sizeof(str),fp1))!=NULL)
  32.     fputs(str,fp2);
  33.     printf("\n Success");
  34.  
  35.     fclose(fp1);
  36.     fclose(fp2);
  37.     getch();
  38. }
Add Comment
Please, Sign In to add comment