Skip to content

Instantly share code, notes, and snippets.

@monzou
Created May 14, 2011 14:59
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 monzou/972298 to your computer and use it in GitHub Desktop.
Save monzou/972298 to your computer and use it in GitHub Desktop.
cat w/ stdio
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int i;
for (i = 1; i < argc; i++) {
FILE *f = fopen(argv[i], "r");
int c;
if (!f) {
perror(argv[i]);
exit(1);
}
while ((c = fgetc(f)) != EOF) {
if (putchar(c) < 0) {
exit(1);
}
}
fclose(f);
}
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment