Advertisement
rafikamal

File Copy

Feb 3rd, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void fileCopy(char *source, char *destination);
  5.  
  6. int main()
  7. {
  8.     char sourceFile[] = "input.txt";
  9.     char destinationFile[] = "output.txt";
  10.    
  11.     fileCopy(sourceFile, destinationFile);
  12.    
  13.     return 0;
  14.    
  15. }
  16.  
  17. void fileCopy(char *source, char *destination)
  18. {
  19.     FILE *fp1, *fp2;
  20.     int ch;
  21.    
  22.     fp1 = fopen(source, "r");
  23.     fp2 = fopen(destination, "w");
  24.    
  25.     if(fp1 == NULL || fp2 == NULL)
  26.     {
  27.         printf("Error opening file.\n");
  28.         exit(1);
  29.     }
  30.    
  31.     while(1)
  32.     {
  33.         ch = fgetc(fp1);
  34.         if(ch == EOF) break;
  35.         else fputc(ch, fp2);
  36.     }
  37.        
  38.     fclose(fp1);
  39.     fclose(fp2);
  40.    
  41.     remove(source);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement