while() {
...
if (y == 1)
{
printf("success\n");
FILE* fp2 = fopen("output.txt", "w");
fprintf(fp2, "%d \n", a);
fclose(fp2);
break;
}
}
If the condition is satisfied, I wanted to print the a value to file and success in program.
Many values of a that satisfies the condition was printed in program, but when I checked the output.txt file, there was only the value of the last a.
The reason for using break; is to break out of the loop when meets the condition.
I want to print all the a's obtained through the loop.
How can I print all a's to a file?