Thursday, 4 December 2014

Program to read a file


#include"myHeader.h"
main(int argc,char **argv)
{
char ch;
int fd;
fd=open(argv[1],O_RDONLY);
if(fd==-1)
{
perror("open");
return;
}
while(read(fd,&ch,1)==1)
{
write(1,&ch,1);
//printf("%c",ch);
}
close(fd);
}
OutPut:
madan@madan-Lenovo-G570:~/madan/osconcepts$ ./a.out madan
welcome madan reddy
hyderabad
always truth wins