delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/20/20:01:12

From: "Florent BUDILLON" <florent AT oih DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: question of flot???
Date: Sun, 20 Feb 2000 21:35:54 +0100
Organization: Aachen University of Technology (RWTH)
Lines: 60
Message-ID: <88pjbq$i4i$1@nets3.rz.RWTH-Aachen.DE>
NNTP-Posting-Host: 137.226.149.42
X-Trace: nets3.rz.RWTH-Aachen.DE 951079098 18578 137.226.149.42 (20 Feb 2000 20:38:18 GMT)
X-Complaints-To: abuse AT rwth-aachen DOT de
NNTP-Posting-Date: 20 Feb 2000 20:38:18 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi, I did this small program to test my input. It's working, but I want to
get a clue in order to avoid the fact that somebody can enter 2 characters
for the second question and of course because I set only one character for
the second question, the second character will be in the first of my third
question. I was clear?
I think I have the same problem when I answer to the first question more
than 1 int, "enter one integer" doesn't stop be written on the screen. How
can I solve the problem. I thought I had to use fflush(stdin) in order to
erase everything from the input stream, but doesn't work.

Thanks for helping me.

here the prog:

#include <stdio.h>

int main(void)

{

 char c[2],move;
 int check=0,x,y,z,stepcode,test;

 clrscr();

 printf("\n\n");

 do {
     printf("\rEnter 1 integer:");
     fflush(stdout);
     test=scanf("%d",&stepcode);
     scanf("*[^\n]");
     if ((stepcode<10)&&(stepcode>0)) check=1;
    } while ((test!=1)||(check==0));


 printf("\nEnter one character:");
 fflush(stdout);
 scanf("%1s",c);
 scanf("*[^\n]");
 move=c[0];

    do {
       printf("\nEnter three integers:");
       fflush(stdout);
       test=scanf("%d%d%d",&x,&y,&z);
       scanf("*[^\n]");
       } while (test!=3);


 printf("\n\nstepcode=%d  move=%c  x=%d  y=%d  z=%d",stepcode,move,x,y,z);

 printf("\n\nPress a key to close the program ...");
 getch();

 exit (0);

}


- Raw text -


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