I am experiencing that calling read_from_fd more than once causes the data to be empty.
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int fd;
void read_from_fd() {
char data[2];
read(fd, data, 1);
data[1] = 0x00;
printf("data %s\n", data);
}
int main(void) {
fd = open("test.txt", O_RDWR);
read_from_fd();
read_from_fd();
read_from_fd();
}
So the first read prints data but the second and third one print something empty.
I guess this has to do something with the memory from char. Is this correct? What do I have to do to fix this?
Bodo