Advertisement
Guest User

Untitled

a guest
Feb 26th, 2015
185
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.  
  3. void main(int argc,char **argv)
  4. {
  5.     FILE *fp1, *fp2;
  6.     char ch;
  7.     int pos;
  8.  
  9.     if ((fp1 = fopen(argv[1],"r")) == NULL)    
  10.     {    
  11.         printf("\nFile cannot be opened");
  12.         return;
  13.     }
  14.     else    
  15.     {
  16.         printf("\nFile opened for copy...\n ");    
  17.     }
  18.     fp2 = fopen(argv[2], "w");  
  19.     fseek(fp1, 0L, SEEK_END); // file pointer at end of file
  20.     pos = ftell(fp1);
  21.     fseek(fp1, 0L, SEEK_SET); // file pointer set at start
  22.     while (pos--)
  23.     {
  24.         ch = fgetc(fp1);  // copying file character by character
  25.         fputc(ch, fp2);
  26.     }    
  27.     fcloseall();    
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement