\"onstdoutin c, without new line. printf(\"CLIENT>\"); doesnot print enything." />
开发者

c stdout print without new line?

开发者 https://www.devze.com 2023-04-05 06:14 出处:网络
开发者_如何学运维iwanttoprint\"CLIENT>\"onstdoutin c, without new line. printf(\"CLIENT>\"); doesnot print enything.
开发者_如何学运维

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>");
}


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.


Call fflush after printf():

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消