#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main() {
FILE* the_file = fopen("test_file_1.txt", "r");
if (the_file == 0) {
perror("Can't open file for reading. \n");
exit(1);
}
char write;
char read;
char temp;
char line[100];
int j, k;
while ((temp = fgetc(the_file)) != EOF)
{
fgets(line, 100, the_file);
//trim beginning space
for (j = 1, k = 0;
line[j] != '\0'; j++, k++) {
line[k] = line[j];
}
line[k] = '\0';
//to remove training \n
line[strcspn(line, "\n")] = 0;
if (temp == 'R') {
read = temp;
printf("Read found with code %s\n", line);
}
else {
write = temp;
printf("Write found with code %s\n", line);
}
}
fclose(the_file);
return 0;
}
R 0000
W 0000
R 0001
W 0001
R 0002
W 0002
R 0003
W 0003
R 0004
W 0004