Hashan
Hashan

Reputation: 185

c stdout print without new line?

i want to print "CLIENT>" on stdout in c, without new line.
printf("CLIENT>");
does not print enything. how do i solve this?

int main (){
printf("CLIENT>");
}

Upvotes: 6

Views: 28126

Answers (3)

Dave Goodell
Dave Goodell

Reputation: 2153

Try fflush(stdout); after your printf.

You can also investigate setvbuf if you find yourself calling fflush frequently and want to avoid having to call it altogether. Be aware that if you are writing lots of output to standard output then there will probably be a performance penalty to using setvbuf.

Upvotes: 9

Igor
Igor

Reputation: 27268

On some compilers/runtime libraries (usually the older ones) you have to call fflush to have the data physically written:

#include <stdio.h>
int main( void )
{
  printf("CLIENT>");
  fflush(stdout);
  return 0;
}

If the data has newline in the end, usually fflush isn't needed - even on the older systems.

Upvotes: 2

MByD
MByD

Reputation: 137432

Call fflush after printf():

int main (){
    printf("CLIENT>");
    fflush( stdout );
}

Upvotes: 5

Related Questions