Implementation of CAT Command in unix


Implementation of CAT Command

Implementation of CAT Command

#include&ltstdio.h&gt
main(int argc,char *argv[]){
int n,i,fd;
char a;
if(argc&lt2)
printf("opration not possible");
for(i=1;i<argc;i++)
{
fd=open(argv[1],0);
if(fd==1)
printf("file open error");
}
n=read(fd,&a,1);
while(n&gt0)
{
write(1,&a,1);
n=read(fd,&a,1);
}
close(fd);
}

output:

-bash-3.2$ cc two.c
-bash-3.2$ cat>l.txt
fdsf
dfggdg
^Z
[3]+ Stopped
cat > l.txt
-bash-3.2$ ./a.out l.txt
fdsf
dfggdg
-bash-3.2$