Last active
October 22, 2015 18:05
-
-
Save akkijp/46ef6716f7f7b9a302ba to your computer and use it in GitHub Desktop.
catコマンドを作る! stdio版
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
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char *argv[]){ | |
int i; | |
if(argc < 2){ | |
fprintf(stderr, "%s: file name not given\n", argv[0]); | |
exit(1); | |
} | |
for(i=1; i<argc; i++){ | |
FILE *f; | |
int c; | |
f = fopen(argv[i], "r"); | |
if(!f){ | |
perror(argv[i]); | |
exit(2); | |
} | |
while((c = fgetc(f)) != EOF){ | |
if(putchar(c) < 0) exit(3); | |
} | |
fclose(f); | |
} | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment