#include <stdio.h>
#include <fcntl.h>
#include <iostream>
using namespace std;
int main()
{
int fd, i, oflag;
char buf[100];
oflag = (O_RDONLY);
fd = open("from4to5", oflag, 0x1c0);
if (fd < 0 ) {printf("Error opening\n"); exit(1);}
while ( (i = read(fd, buf, 16)) != 0 ) {
cout << "child: # bytes read which were: " << buf <<endl;
};
close(fd);
return 0;
}
Say I have a file called 'from4to5' with contents like this.
BD8d3700indiaC#EBD6d4700godgeD3EBD9d1311badge3TE
I have to read 16 bytes using the low-level function call read() (in C). After I read the first 16 bytes, the next time I need to read from the same file, I'll only have to read it from until the point it was read before..
How do I accomplish that ? The code snippet, by the way, reads until EOF occurs, 16 bytes a time.