Last active
December 16, 2015 15:49
-
-
Save halit/5459080 to your computer and use it in GitHub Desktop.
My cat program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * ===================================================================================== | |
| * | |
| * Filename: cat.c | |
| * | |
| * Description: My cat program | |
| * | |
| * Version: 1.0 | |
| * Created: 25-04-2013 13:58:45 | |
| * Compiler: gcc | |
| * | |
| * Author: Halit Alptekin, info@halitalptekin.com | |
| * | |
| * ===================================================================================== | |
| */ | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int main(int argc, char *argv[]) | |
| { | |
| FILE *ip; | |
| char *fname = argv[0]; | |
| void copyFile(FILE *, FILE *); | |
| if(argc == 1){ | |
| copyFile(stdin, stdout); | |
| }else{ | |
| while(--argc > 1){ | |
| if((ip = fopen(*++argv, "r")) != NULL){ | |
| copyFile(ip, stdout); | |
| fclose(ip); | |
| }else{ | |
| fprintf(stderr, "%s: dosya acilamadi %s\n",fname, *argv); | |
| exit(1); | |
| } | |
| } | |
| } | |
| if(ferror(stdout)){ | |
| fprintf(stderr, "%s: standart cikis hatasi\n", fname); | |
| exit(2); | |
| } | |
| return 0; | |
| } | |
| void copyFile(FILE *ifp, FILE *ofp){ | |
| int c; | |
| while((c = fgetc(ifp)) != EOF) fputc(c, ofp); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment