#include <stdio.h>
#include <assert.h>
int main(void)
{
FILE* tmpf = tmpfile();
fputs("text in file\n", tmpf);
rewind(tmpf);
for (int ch; (ch = fgetc(tmpf)) != EOF; putchar(ch)) {}
assert(feof(tmpf)); // the for loop above terminate by EOF
puts("End of file reached");
clearerr(tmpf); // clear EOF
puts(feof(tmpf) ? "EOF set" : "EOF cleared");
}
/*
run:
text in file
End of file reached
EOF cleared
*/