code_debug
code_debug

Reputation: 25

How to execute a function call quietly in c programming as per the following code?

/*------Prints debug statements------*/
void d_printf(char *str)
{
  debug_printf("\n -------------------------------------------------");
  debug_printf(" \t \n \n %s \t ",str);
  debug_printf("\n -------------------------------------------------");
  return;
}

int abc(arg1, arg2)
{
 d_printf("bleh bleh");
  happy (a, b); 
printf("Hello world");
}

int happy(arg1, arg2)
{
 //do something
 //assuming this contains no print statments.
}

I want the happy function to execute quietly and the rest of the things should be printed ? (The happy function should execute quietly in the background, i.e, whatever happens in that function should not be seen on terminal.)

Upvotes: 0

Views: 250

Answers (1)

Alex Riveron
Alex Riveron

Reputation: 411

As long as your happy function is not calling any functions that write to standard output, then it shouldn't be writing anything to your terminal.

I'm assuming you still want your other functions to write to the terminal.

You also seem to be calling the happy function with the a and b variables as arguments, but it doesn't seem like you've instantiated those anywhere in your code. You're also missing the type specifiers for the arg1 and arg2 parameters in your happy and abc functions.

You could also redirect standard output as @Lundin suggested in his comment. I believe that there are OS specific calls for doing so in C, like freopen_s, and _wfreopen_s to reassign the stdout file pointer in Windows and dup2 to reassign the stdout file descriptor in Linux.

Upvotes: 1

Related Questions