Hi all,
I have problem with read() function. It doesn't read at all. Always return -1. my code is like below:
Code:
void myRead()
{
int fd,ret;
char buf[BUFSIZ];
fd = open("sam.txt" , O_WRONLY);
if (fd == -1)
{
printf("Error in openning the file!\n");
exit(0);
}
//read the file
ret = read(fd,buf,BUFSIZ);
if (ret == -1)
{
printf("Error in reading!\n");
exit(0);
}
close(fd);
}
I am sure file can be open, but once start to read it always return -1.
Please suggest or comment. Thanks a lot.
--Mario.
Code Tags added by Kermi3