Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* basic operations with files */
- /* pointer arithmetics:
- *
- * push(pointer, v) INDICATES *(pointer++) = v
- * pop(pointer) INDICATES *(--pointer)
- * (*++v)[0] INDICATES (**++v)
- * INDICATES first char in v
- * INDICATES name of string/vector v
- * likewise, *v[0] INDICATES **v
- * and *v[n] INDICATES **(v + n)
- * returntype (*funct)(args) INDICATES a function funct with arguments args which returns...
- * char **argv INDICATES pointer to char pointer
- * int(*v)[len] INDICATES pointer "v" to a vector of "len" int elements
- * int *v[len] INDICATES vector "v" of "len" pointers to int elements
- * void *funct() INDICATES function "funct" that returns a pointer-to-void
- * void (*funct)() INDICATES pointer to a function "funct" that returns void
- *
- */
- /* useful characters: [] # */
- # include <stdio.h>
- void filecopy(FILE * orig, FILE * copy);
- int main(int argc, char * argv[])
- {
- FILE * file;
- while(--argc > 0) // length of file
- {
- if((file = fopen(*++argv, "r")) == NULL) // if the file is the last one in the batch...
- return 1; // ...exits successfully
- else
- {
- filecopy(file, stdout); // otherwise, copies another file
- fclose(file); // then closes it
- }
- }
- return 0; // exits
- }
- void filecopy(FILE * orig, FILE * copy)
- {
- int ch;
- //while((ch = getchar(orig)) != EOF) // BOOK VERSION, generates compiling error
- while((ch = getchar()) != EOF) // copies chars until the end of file
- putc(ch, copy);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement