Skip to content

Instantly share code, notes, and snippets.

Created February 18, 2013 19:19
Show Gist options
  • Save anonymous/4979855 to your computer and use it in GitHub Desktop.
Save anonymous/4979855 to your computer and use it in GitHub Desktop.
Wooo! Gists!
Errors:
-) There is a buffer overflow when passing words of length >= 100.
-) There is a problem for words containing "%s".
-) The file descriptor is never closed.
-) All whitespace is removed.
#include <stdio.h>
#include <stdlib.h>
#define SUCCESS 0
#define E_PARAM 1
int main(int argc, char **argv)
{
int i;
FILE *in;
char c;
if(argc==0)
{
fprintf(stderr, "ERROR: Not enough parameters.\n");
fprintf(stderr, "Syntax: %s [file1] [file2] ... [fileN]\n", argv[0]);
exit(E_PARAM);
}
for(i=1;i<argc;i++)
{
in = fopen(argv[i], "r");
if(in==NULL)
fprintf(stderr, "\n%s: %s: No such file or directory\n", argv[0], argv[i]);
else while ((c = fgetc(in)) != EOF)
{
putchar(c);
}
fclose(in);
}
exit(SUCCESS);
}
goodcat: goodcat.o
cc goodcat.o -o goodcat
clean:
rm goodcat.o goodcat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment