I have created a mini example to test the fgets() utility but when i run this example i don't see any output in the shell, below is my example: #include <stdio.h> int main () { FILE *fp, *fd_3, *fd_2; char str[60]; char str1[] = "writing to file "; char str2[] = "my file"; fp = fopen("file/test_fopen" , "w"); fclose(fp); fd_3 = fopen("file/test_fopen" , "r"); fp = fopen("file/test_fopen" , "a"); fwrite(str1 , 1 , sizeof(str1) , fp); if( fgets (str, 60, fd_3)!=NULL ) { puts(str); } fclose(fp); fd_2 = fopen("file/test_fopen" , "a"); fwrite(str2 , 1 , sizeof(str2) , fd_2); if( fgets (str, 60, fd_3)!=NULL ) { puts(str); } fclose(fd_2); return(0); } When i compile and run this code against glibc-2.17 i receive an output "writing to file" on the shell but when i compile against glibc-2.28, there is no output. So is this an expected behavior? is the way of flushing when calling fclose() changed between the two versions?
This is because EOF is now sticky, see commit 2cc7bad0ae. You need to call fseek or clearerr before you can read more from a changing file.
(In reply to Andreas Schwab from comment #1) > This is because EOF is now sticky, see commit 2cc7bad0ae. You need to call > fseek or clearerr before you can read more from a changing file. Thanks Andreas, i have called clearerr and it solved the issue.
Closing per comment 1 and comment 2.