delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/08/26/12:39:33

Date: Wed, 26 Aug 1998 13:41:34 -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
Subject: Re:
In-Reply-To: <35CA4428.27B48B43@cartsys.com>
Message-ID: <Pine.LNX.3.96.980826133938.20248A-100000@apolo.lsi.usp.br>
MIME-Version: 1.0

Dear colleagues,

Please help me with this problem: the following program should run
correctly, and it runs in others compilers.
But in DJGPP we had problems when our programs use scanf("%c", &x)
mixed with scanf("%d", &y) or scanf("%f", &z), the first one is
not runned sucessfully.
I tried to use fflush(stdin), but, like Nate Eldredge told me,
"ANSI says that the effect of fflush'ing an input stream is undefined",
and this idea didn't work.
What could be the correct way to use scanf safely?

Thank you in advance.


Carlos Menezes.



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

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

 if (c=='y') c=a*b;
 else        c=a+b;

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


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