Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote