Skip to content

Instantly share code, notes, and snippets.

@akkijp
Last active October 22, 2015 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akkijp/46ef6716f7f7b9a302ba to your computer and use it in GitHub Desktop.
Save akkijp/46ef6716f7f7b9a302ba to your computer and use it in GitHub Desktop.
catコマンドを作る! stdio版
#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