i am new to unix.
i have written a code for testing the basic functions
read / write and open
i have read that read/write returns the no of bytes read/written but
here my write is returning 1 and read is returning 0 no matter how many
chars i write.
could not rectify where is the problem
plz help me.
#include<stdio.h>
#include<fcntl.h>
int main()
{
int fd , nob;
char buf[30],rbuf[30];
fd = open( "Ux1", O_CREAT| O_RDWR | O_TRUNC, 0777);
if(fd<0)
{ printf("cannot create file\n");
exit(0);
}
printf(" fd =%d",fd);
printf("Enter Sth\n");
fgets(buf, sizeof(buf), stdin);
if(nob = write ( fd , buf, sizeof(buf)) > 0)
printf ( "%d bytes written \n",nob);
nob = read (fd , rbuf, sizeof(rbuf)) ;
printf ( "%d bytes read \n",nob);
printf(" %s\n",rbuf);
close(fd);
return 0;
}