I'm going to move the answer from comments to answer, but as a Community Wiki. I wouldn't want to write some "pseudo-definitive" answer which was really a stab in the dark, as this is.
Based on the symptom of output not appearing on the terminal, I suggested that you add fflush(stdout)
prior to the getchar()
call. The fflush()
is a standard C library function which "flushes" pending output or input.
I just guessed that your printf()
output was going into a buffer and that calling fflush(stdout)
would cause that buffer to be sent to the terminal, solving your symptom.
You could possibly use the following macro and variadic function to allow that you will fflush
after every printf
:
/*
* If the environment supplies vfprintf():
*/
#define printf my_printf
int my_printf(const char * fmt, ...)
{
int ret_val;
va_list var_args;
va_start(var_args, fmt);
ret_val = vfprintf(stdout, fmt, var_args);
va_end(var_args);
fflush(stdout);
return ret_val;
}
otherwise maybe:
/* If the environment lacks vfprintf() */
#define my_printf(args) ((void)printf args, (void)fflush(stdout))
/*
* Usage:
*
* my_printf(("Format %s\r\n", "string"));
*
*/