You need to close the end of the letter, not just clear it. Otherwise, it fscanf()does not know if there is more data to read (more digits):
fprintf(write_file, "%d", 100);
fclose(write_file);
fscanf(read_file, "%d", &x);
Alternatively, write a space after the numbers to fscanf()stop looking for more numbers:
fprintf(write_file, "%d ", 100);
fflush(write_file);
fscanf(read_file, "%d", &x);
This should fix the problem.
source
share