www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/11/13/04:45:21

From: "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk>
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Mon, 13 Nov 1995 09:21:52 GMT
Subject: Re: stupid C question (flushing stdout)

  "J. A. McNamara" <grulm AT netaxs DOT com> wrote:-
> I find that when I do a printf, or putchar, nothing appears on the screen
> until I send a "\n" to standard output ... So, is there any way to force the
> buffer to flush to standard output without a newline?

  fflush(stdout);

  Also, in Gnu C/C++ stdout's buffer is automatically flushed when anything is
read from stdin (usually = from the keyboard), so these will work:-

  printf("name of experiment?"); gets(exptname);

  double ask(char*s) {double x; char buf[512];
  X: printf(s); gets(buf); if(sscanf(buf,"%lf",&x)<1) goto X; return x;}
  ...
  weight=ask("weight of sample?");

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019