www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/05/22/15:58:32

Message-ID: <39298E3C.99DCB2A1@mail.owc.net>
Date: Mon, 22 May 2000 14:45:00 -0500
From: 2711 <krakxl AT mail DOT owc DOT net>
X-Mailer: Mozilla 4.5 [en] (Win95; I)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Getchar problems in while() loop.
Reply-To: djgpp AT delorie DOT com

Hey, thank you for reading my message, I'm having problems with a little
educational program I wrote,
The magic number is obviously five, but when it is entered, like any
other value,

guess the magic number *beeep*
guess the magic number *beeep*

is displayed.

#include <stdio.h>

void main(void)
{
int stop;

        while ((stop=getchar())!= 5)
        {
         printf("Guess the magic number\n\a");
         stop=getchar();
        }
}

I tried using two variables, one a char;, and atoi, but the the same
results were encoutered. I also tried removig all references pertaining
to "getchar", declaring the while loop "while(stop !=5)", and using
"scanf" in the body of the loop, but to no avail.

Is this a bug (?) or am I a moron (most likely)?

Thank you much for your time

---dave

- Raw text -


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