When I run my code I am supposed to read a file and get: 1 Joe Sf 23 main st. 23
ID: 651008 • Letter: W
Question
When I run my code I am supposed to read a file and get:
1 Joe Sf 23 main st. 234-4333
but I get:
1 Joe Sf 23 main st. 234-4333
Joe Sf 23 main st. 234-4333
I dont have another print statement or anything. Why is it printing again?
Here is the code?
case 'w':
file = fopen(commandOption,"w");
i = 0;
for(i = 0; i < counter; i++)
{
fprintf(file,"%s",array[i]);
fflush(stdout);
}
fclose(file);
break;
Explanation / Answer
Please add the whole program for exact answer.
But I think output is still printed because you set the value of commandOption to your standard output, and when you try to print using fprintf, it comes to the standart output because commandOption is passed as a parameter in fprintf. Please check that once!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.