TAHMID37

Binary stream

Jul 13th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. /*  TAHMID RAHMAN
  2.     DAMIAN FOREVER
  3.      MATH LOVER
  4.     NEVER GIVE UP
  5. */
  6.  
  7. #include<stdio.h>
  8. #include<stdlib.h>
  9. int main(int argc, char *argv[])
  10. {
  11.     FILE *from, *to;
  12.     char ch;
  13.  
  14.     if(argc!=3)
  15.     {
  16.         printf("Usage: copy<source><destination>");
  17.         exit(1);
  18.     }
  19.  
  20.     if((from=fopen(argv[1], "rb"))==NULL)
  21.     {
  22.         printf("Can't open file.\n");
  23.         exit(1);
  24.     }
  25.  
  26.     if((to=fopen(argv[2], "wb"))==NULL)
  27.     {
  28.         printf("Can't open file.\n");
  29.         exit(1);
  30.     }
  31.  
  32.     while(!feof(from))
  33.     {
  34.         ch=fgetc(from);
  35.         if(ferror(from))
  36.         {
  37.             printf("Error reading source file.\n");
  38.             exit(1);
  39.         }
  40.         if(!feof(from))
  41.         {
  42.             fputc(ch, to);
  43.         }
  44.         if(ferror(to))
  45.         {
  46.             printf("Error writing destination file.\n");
  47.             exit(1);
  48.         }
  49.     }
  50.     if(fclose(from)==EOF)
  51.     {
  52.         printf("Error closing source file.\n");
  53.         exit(1);
  54.     }
  55.  
  56.     if(fclose(to)==EOF)
  57.     {
  58.         printf("Error closing destination file.\n");
  59.         exit(1);
  60.     }
  61.     return 0;
  62. }
Add Comment
Please, Sign In to add comment