why printf don't work?

I use Solaris 10, I use following code:

#include <signal.h>
int main(void){
  printf("----------testing-----------");
  if(signal(SIGUSR1,sig_usr)==SIG_ERR)
    err_sys("can't catch SIGUSR1");
  for(;;)
    pause();
sig_user(int signo){
  .....
}

when I run above code,it print nothing in screen.Why?
After I delete line

if(signal(SIGUSR1,sig_usr)==SIG_ERR)

it can print

----------testing-----------

Where is wrong in my above code?

Thanks

The printf() library call prints to stdout, which is buffered. You won't see any output until you either fill up or flush the buffer. IIRC you can flush stdout with "fflush( stdout );". That should work - or it's something close to that. Or you an print to stderr using "fprintf( stderr, "Your message here" );" as stderr is not buffered.

Or, make stdout unbuffered for a while

Another way to flush the buffer would be to add a newline at the end of the printf...

printf("----------testing-----------\n");