SHARE
TWEET

cycki

a guest Mar 20th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4.  
  5.  
  6. int main(int argc, char ** argv)
  7. {
  8.     FILE * filer, * filew;
  9.     int numr,numw;
  10.  
  11.        
  12.     if((filer=fopen(argv[1],"rb"))==NULL){
  13.         fprintf(stderr, "open read file error.\n");
  14.         exit(1);
  15.     }
  16.    
  17.     if((filew=fopen(argv[2],"wb"))==NULL){
  18.         fprintf(stderr,"open write file error.\n");
  19.         exit(1);
  20.     }
  21.     int temp=0;
  22.     sscanf(argv[3],"%d", &temp);
  23.        
  24.  
  25.     char *buffer;
  26.     buffer = (char *) malloc(sizeof(char)*temp);
  27.  
  28.  
  29.  
  30.    
  31.  
  32.    
  33.     while(feof(filer)==0){
  34.     if((numr=fread(buffer,1,temp,filer))!=temp){
  35.         if(ferror(filer)!=0){
  36.         fprintf(stderr,"read file error.\n");
  37.         exit(1);
  38.         }
  39.         else if(feof(filer)!=0);
  40.     }
  41.     if((numw=fwrite(buffer,1,numr,filew))!=numr){
  42.         fprintf(stderr,"write file error.\n");
  43.         exit(1);
  44.     }
  45.     }  
  46.    printf("%d", numr);
  47.    printf("\n%d", numw);
  48.     fclose(filer);
  49.     fclose(filew);
  50.    
  51.    free(buffer);
  52.     return 0;
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top