#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main( void )
{
int fd,nob;
char str[1024];
fd = open("test.txt",O_RDWR|O_CREAT,S_IRWXU);
if (fd < 0) {
perror("open:");
exit(0);
}
nob = write(fd,"hello first",1024);
close(fd);
printf(" %d nob written",nob);
fd = open("test.txt",O_RDWR);
nob = read(fd,str,1024);
close(fd);
printf(" %d nob read",nob);
printf(" %s \n", str);
return 0;
}
The above code outputting 1024 nob written 1024 nob read hello first
on the terminal.
when i say cat test.txt the file contents are hello first %d nob written %d nob read %s
i heard about buffering , is it because of that , but i am closing the files immediately i finish the file operation.
any suggestions or help please...