top of page

1  #include<stdio.h>
2  #include<stdlib.h>
 
3  int main(int argc, char *argv[ ] /* char **argv */ ){
 
4     FILE *source, *target;
5     int c;
 
6     if( (source=fopen(*++argv, "rb")) == NULL) {
 
7        fprintf(stderr, "Can't open source file!\n");
8        exit(1);
9     }
 
10 #ifdef WRITE_TO_FILE
 
11    if(argc != 3) {
12       fprintf(stderr,"use : cpfile source target\n");
13       exit(1);
14    }
 
15    if(! (target=fopen(*++argv, "wb"))){
16       fprintf(stderr,"Can't open target file!\n");
17       exit(1);
18    }
 
19    while((c=fgetc(source)) != EOF) {
20       fputc(c, target);
21    }
22    fclose(target);
 
23 #else
 
24    if(argc != 2) {
25       fprintf(stderr,"use : cpfile source\n");
26       exit(1);
27    }
 
28    while( (c=fgetc(source)) != EOF)
29       fputc(c, stdout);
 
30 #endif
31    fclose(source);
32    return 0;
33 }

  • b-facebook
  • Twitter Round
  • b-googleplus
bottom of page