www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/08/27/09:18:39

Date: Thu, 27 Aug 1998 10:21:03 -0300 (EST)
From: Carlos Eduardo Dantas de Menezes <menezes AT lsi DOT usp DOT br>
To: Nate Eldredge <nate AT cartsys DOT com>
cc: dj AT delorie DOT com, djgpp-workers AT delorie DOT com, Vik DOT Heyndrickx AT rug DOT ac DOT be,
George Foot <george DOT foot AT merton DOT oxford DOT ac DOT uk>
Subject: Re:
In-Reply-To: <35CA4428.27B48B43@cartsys.com>
Message-ID: <Pine.LNX.3.96.980827101948.4314B-100000@apolo.lsi.usp.br>
MIME-Version: 1.0

Dear colleagues,

Please excuse me. There was a mistake in that program:

#include<stdio.h>
main()
{
 int a, b, c;
 char d;

 scanf("%d%d", &a, &b);
 scanf("%c", &d);

 if (d=='y') c=a*b;
/*   ^
      \_ in original was 'c'
*/
 else        c=a+b;

 printf("\n%d\n", c);
}

Thanks to George Foot by let me see this!
The (reformulated) problem is: what could be the best way to clean
the buffer (Nate Eldredge told me that "ANSI says that the effect of 
fflush'ing an input stream is undefined") to the second scanf call
doesn't read next character typed just after the second number, if
it is newline?

Excuse me my mistakes and thank you in advance!


Carlos Menezes  -- Tycho Brahe Project 
LABORATORIO DE SISTEMAS INTEGRAVEIS.
ESCOLA POLITECNICA DA UNIVERSIDADE DE SAO PAULO.
E-MAIL: menezes AT lsi DOT usp DOT br
URL:    http://www.lsi.usp.br/~menezes/menezes.html                            

- Raw text -


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