Here is the simple code after fflush() we are not getting the expected output. We expect "Hello World file2" but it is showing some random garbage value as mentioned below.
FILE 2 b4 = output_reg : P\ufffd\ufffdr\ufffd
FILE 2 af = output_reg : P\ufffd\ufffdr\ufffd
#include <stdio.h>
int main(void) {
char output_reg[300], errstr[300];
FILE *fd1, *fd2, *fd3, *fd4;
char *retno, *retseek;
int len;
fd4 = fopen("out2.log","w");
fd3 = fopen("out2.log","r");
fputs("Hello World file2!\n", fd4);
fgets(output_reg, 30, fd3);
printf("FILE 2 b4 = output_reg : %s\n",output_reg);
fflush(fd4);
fgets(output_reg, 30, fd3);
printf("FILE 2 af = output_reg : %s\n",output_reg);
}