#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include <stdlib.h>
void printfile(char *file);
int main(int argc, char *argv[])
{
if (argc==1)
{
fprintf(stderr, "usage: printfiles file1 [file2 ...]\n file1, file2, etc.: files to print\n");
exit(EINVAL);
}
int i;
for (int i = 1; i < argc; ++i)
{
printfile(argv[i]);
}
exit(0);
return 0;
}
void printfile(char *file){
assert(file!=NULL);
FILE *fp = fopen(file, "rb");
if (!fp)
{
fprintf(stderr, "Can't open input file %s!\n", file);
exit(ENOENT);
}
char buff;
while (!feof(fp)){
buff = fgetc(fp);
printf("%c", buff);
}
printf("\n");
fclose(fp);
}
Comments