I had written the following code which does the following:
It takes in a series of integers as input.
It prints all the integers that come before 42 has been input (assumes that the user inputs 42 at some point of time) to the screen as well as to a file named out.txt.
The printing to the screen is done by reading from the out.txt file.
While printing to the screen, I found that the last integer was being printed twice (on screen) even though the output of the text file is correct. Why is this ?
fp1 = fopen("out.txt", "w");
if(n == 42)
fprintf(fp1, "%d\n", n);
fp1 = fopen("out.txt", "r");
fscanf(fp1, "%d", &n);