Skip to content

Instantly share code, notes, and snippets.

@karno
Created October 23, 2010 13:25
Show Gist options
  • Save karno/642202 to your computer and use it in GitHub Desktop.
Save karno/642202 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void ReadFile(char* fname)
{
FILE *fp;
char buf[1024];
if ((fp = fopen(fname, "r")) == NULL)
{
fprintf(stderr, "File not found:%s\n", fname);
return;
}
printf ("\n\nFile:%s\n\n", fname);
int cnt = 1;
while (fgets(buf, 256, fp) != NULL)
{
printf("%3d: >> %s", cnt, buf);
cnt++;
}
fclose(fp);
}
int main(int argc, char* argv[])
{
if (argc < 2)
{
fprintf(stderr, "No argument!");
exit(-1);
}
else
{
int i = 1;
for (i = 1; i < argc; i++)
{
ReadFile(argv[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment