Created
September 4, 2011 21:02
-
-
Save alcides/1193507 to your computer and use it in GitHub Desktop.
A cat clone in naïve C.
This file contains 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 <stdlib.h> | |
#include <stdio.h> | |
char *buffer; | |
void read(char* fname) { | |
FILE *fp = fopen(fname, "r"); | |
if (fp != NULL) { | |
fseek(fp, 0L, SEEK_END); | |
long s = ftell(fp); | |
rewind(fp); | |
buffer = malloc(s); | |
fread(buffer, s, 1, fp); | |
fwrite(buffer, s, 1, stdout); | |
if (fp != NULL) fclose(fp); | |
free(buffer); | |
} | |
} | |
int main(int argc, char** argv) { | |
int f; | |
for(f=1; f<argc; f++) { | |
read(argv[f]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment