Advertisement
heavenriver

filecopy.c

Nov 25th, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 KB | None | 0 0
  1. /* basic operations with files */
  2.  
  3.  /* pointer arithmetics:
  4.   *
  5.   * push(pointer, v) INDICATES *(pointer++) = v
  6.   * pop(pointer) INDICATES *(--pointer)
  7.   * (*++v)[0] INDICATES (**++v)
  8.   *           INDICATES first char in v
  9.   *           INDICATES name of string/vector v
  10.   * likewise, *v[0] INDICATES **v
  11.   *       and *v[n] INDICATES **(v + n)
  12.   * returntype (*funct)(args) INDICATES a function funct with arguments args which returns...
  13.   * char **argv INDICATES pointer to char pointer
  14.   * int(*v)[len] INDICATES pointer "v" to a vector of "len" int elements
  15.   * int *v[len] INDICATES vector "v" of "len" pointers to int elements
  16.   * void *funct() INDICATES function "funct" that returns a pointer-to-void
  17.   * void (*funct)() INDICATES pointer to a function "funct" that returns void
  18.   *
  19.   */
  20.  
  21.  /* useful characters: [] # */
  22.  
  23.  # include <stdio.h>
  24.  
  25.  void filecopy(FILE * orig, FILE * copy);
  26.  
  27.  int main(int argc, char * argv[])
  28.     {
  29.       FILE * file;
  30.       while(--argc > 0) // length of file
  31.       {
  32.        if((file = fopen(*++argv, "r")) == NULL) // if the file is the last one in the batch...
  33.           return 1; // ...exits successfully
  34.        else
  35.           {
  36.            filecopy(file, stdout); // otherwise, copies another file
  37.            fclose(file); // then closes it
  38.           }
  39.       }
  40.      return 0; // exits
  41.     }
  42.    
  43. void filecopy(FILE * orig, FILE * copy)
  44.     {
  45.      int ch;
  46.      //while((ch = getchar(orig)) != EOF) // BOOK VERSION, generates compiling error
  47.      while((ch = getchar()) != EOF) // copies chars until the end of file
  48.     putc(ch, copy);
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement