50 lines
978 B
C
50 lines
978 B
C
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <sys/wait.h>
|
|
#include <string.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
|
|
int main() {
|
|
|
|
extern int errno;
|
|
|
|
char file[] = "temp";
|
|
|
|
// opening file
|
|
int desc_f = open(file, O_RDONLY);
|
|
if (desc_f < 0) {
|
|
perror("ERROR opening f_write.txt");
|
|
exit(errno);
|
|
}
|
|
|
|
// reading to file
|
|
|
|
while (1) {
|
|
int buf;
|
|
for (int i = 0; i < 10; i++) {
|
|
int ret_read = read(desc_f, &buf, sizeof(int));
|
|
if (ret_read < 0) {
|
|
perror("ERROR reading to f_write.txt");
|
|
exit(errno);
|
|
}
|
|
printf("%d\n", buf);
|
|
}
|
|
sleep(1);
|
|
system("clear");
|
|
lseek(desc_f, 0, SEEK_SET);
|
|
}
|
|
|
|
// closing files
|
|
|
|
int ret_close = 0;
|
|
ret_close = close(desc_f);
|
|
if (ret_close < 0) {
|
|
perror("ERROR closing f_read.txt");
|
|
exit(errno);
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|