Mail Archives: djgpp/2000/05/22/16:46:55
djgpp AT delorie DOT com (2711) wrote in <39298E3C DOT 99DCB2A1 AT mail DOT owc DOT net>:
>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)
please see question 1.25b in the comp.lang.c faq available at
http://www.faqs.org/faqs/C-faq/faq/.
>{
>int stop;
>
> while ((stop=getchar())!= 5)
> {
> printf("Guess the magic number\n\a");
> stop=getchar();
> }
>}
>
the following would do something sorta good enough:
#include <stdio.h>
int main(void) {
while( getchar() != '5' )
puts("Guess the magic number:");
return 0;
}
however, the correct prompt in this case is "Guess the magic character",
not magic number.
for a simple example of parsing numbers typed on the command line, you can
take a look at http://unur.com/howto/c-examples.html.
hth.
Sinan.
--
mailto:Sinan_Unur AT mail DOT com
http://unur.com/sinan/
- Raw text -