Well if you know when you want it to be "silent" and when you want it not to be then you may want to take a look at freopen() to reassign std output, aka stdout, to something other than the monitor.
Here is the description for freopen:
Code:
FILE *freopen(
const char *path,
const char *mode,
FILE *stream
);
Parameters
path
Path of new file.
mode
Type of access permitted.
stream
Pointer to FILE structure.
Return Value
Each of these functions returns a pointer to the newly opened
file. If an error occurs, the original file is closed and the function
returns a NULL pointer value.
Remarks
The freopen function closes the file currently associated with
stream and reassigns stream to the file specified by path.
_wfreopen is a wide-character version of _freopen; the path and
mode arguments to _wfreopen are wide-character strings.
_wfreopen and _freopen behave identically otherwise.
And here is a sample prog that demonstrates its use:
Code:
#include <stdio.h>
#include <stdlib.h>
void redirectStream(char*, char*, FILE*);
void printStream(char*);
int main(void){
printf("\nCurrently stdout is the monitor. Redirecting stdout.\n");
//redirect stdout to a file
redirectStream("newStream.txt", "a+", stdout);
printf("These statements are going to the new stdout\n");
printf("This will appear in our file newStream.txt\n");
//now we restore stdout and print out our file
redirectStream("CON", "w", stdout);
printf("\nRedirecting stream to monitor. Displaying file contents\n\n");
printStream("newStream.txt");
return 0;
}
void redirectStream(char* fileName, char* mode, FILE* stream){
freopen(fileName, mode, stream);
}
void printStream(char* fileName){
char line[80];
FILE* myFile;
int i = 1;
myFile = fopen(fileName, "r");
if(myFile == NULL){
printf("Error opening file");
return;
}
while(fgets(line, 80, myFile) != NULL){
printf("%d. %s", i++, line);
}
fclose(myFile);
}