cat command simulation


//Simulation of cat command

#include<stdio.h>

#include<stdlib.h>

void printfile(FILE *f)

{

char str[80];

while(fgets(str,80,f))

printf(“%s”, str);

}

int main(int argc, char *argv[])

{

char str[80];

FILE *f;

if(argc<2)

printfile(stdin);

else

{

int i;

for(i=1; i<argc; i++)

{

if(!(f = fopen(argv[i], “rt”)))

perror(argv[i]);

else

printfile(f);

fclose(f);

}

}

}

Advertisements