-3

say a I have a function with many printf statements and at the end of it I want to add an option to save the already printed items to a text file.

Ex:

void print_Items(float a, float b, float c){

printf("%f", a);
printf("%f", b);
printf("%f", c);

printf("s", "Press s to save above list to a file or q to quit");

ch = getchar();

switch (ch){

 case 's':
     PRINT TO FILE
     break;

 case 'q':
     break;

}

I want to avoid creating another similar function that just specifically generates and prints the same contents to a file

Digvijaysinh Gohil
  • 1,367
  • 2
  • 15
  • 30

1 Answers1

0

Ideally all the print statements are pushed into a txt file through the command line using an example like :

test.exe > stdout.txt

Take a look at this link

Writing ALL program output to a txt file in C++

freopen() should allow you to use the switch case to enable a debug of sorts and push all the print statements into a txt file.

Cyrus Dsouza
  • 883
  • 7
  • 18