Wednesday, 20 February 2013

Program:To implement in c the following unix commands using standard i/o and system calls 1.cat

Program:To implement in c the following unix commands using standard i/o and system calls
         1.cat


#include
#include
main(int argc,char *argv[])
{
int i;
char ch;
FILE *fp;
for(i=1;i{
fp=fopen(argv[i],"r");
if(fp==NULL)
printf("\n FILE DOES NOT EXIST");
else
{
while(!feof(fp))
{
ch=fgetc(fp);
printf("%c",ch);
}
}        fclose(fp);
printf("\n\n");
}
}




/*--------------------------INPUT/OUTPUT--------------

-bash-3.2$ vi mycat.c
-bash-3.2$ cc mycat.c -o mycat
-bash-3.2$ ./mycat hello.c
unix is a operating system

------------------------------------------------*/

No comments:

Post a Comment