Program for printing file contents on standard output which are passed as command line argument

#include <stdio.h>
void putfile(FILE *);
int main(int argc,char *argv[])
{
FILE *fp;
int i=1;

if(argc>1)
{
while(--argc)
{
if((fp=fopen(argv[i++],"r"))==NULL)
{
fprintf(stderr,"can't open %s \n",argv[i-1]);
continue;
}
putfile(fp);
fclose(fp);
}
}
else putfile(stdin);
}
void putfile(FILE *fp)
{
int ch;
while((ch=getc(fp))!=EOF)
putchar(ch);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s