Is there a way for a program to write to a txt file while running? I've created a simple program that can write to a text file using fprintf()
but I can only view the written data after the program has been terminated? Is there a way for it to write simultaneously? For simplicity, assume variables and functions declared.
My code goes something like this:
typedef char STRING50[51];
STRING50 sentence;
do {
TransferToText(sentence); // so that after the encode, it goes back here to write to the text file.
showChoices(); //show choices
// A. Write to a txt file
// B. Exit
// CHOICE:
fflush(stdin);
scanf(" %c, &cChoice);
switch (cChoice) {
case 'A':
case 'a':
Encode(sentence); // a function that asks the user to input to a string.
tryAgain = 1;
break;
case 'B':
case 'b':
tryAgain = 0;
break;
default:
tryAgain = 1;
break;
}
} while (tryAgain == 1);
I run the program, after entering an input for the Encode() function, I expect that it should have written to the txt file already but, it's blank. Only if I terminate the program does it show.
If you have a suggested code also for the program in general not just the answer, please educate me.