http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scanf function



============================================================
Feeling blue about the state of your email inbox? Then
you'll be tickled pink to hear about our free email
organization solution. Learn more at
http://click.topica.com/caaabBybUrGczbU68iFa/register
============================================================

scanf("%c%*c", &c);

That should do it.

The * is an assignment suppression, so it reads in the '\n', but doesn't
store it to a variable.
You might want to experiment w/ fflush(stdin) too.

Hope this helps :)

~Greg


----- Original Message -----
From: russ <nupc@nupc.org>
To: <gameprogrammer@topica.com>
Sent: Friday, March 30, 2001 11:59 AM
Subject: scanf function


> --- Sponsor's Message --------------------------------------
> Need Tech Help?
> Fret no more. Get quick answers on our Q&A tech forum!
> http://click.topica.com/caaaa4NbUrGczbU6XLXa/rebootmypc
> ------------------------------------------------------------
>
> hi gang,
>
> ok, here's the general code:
>
> do
> {
> char choice;
> printf( "Enter 'a', 'q', or 'f': " );
> scanf( "%c" &choice );
> printf( "Your choice was: %c", choice );
> if( choice == 'a' ) ...
> if( choice == 'f' ) ...
> }while (choice != 'q' )
> printf( "Finished" );
>
> the problem is when i go through this loop it goes through it twice
> because on scanf() it takes the char as input AND the newline (ie '\n').
>
> so an example output would be:
>
> Enter 'a', 'q', or 'f': e
> Your choice was: e
> Enter 'a', 'q', or 'f':       <- the input is the newline from the "e"
> Your choice was:              <- output is the newline ("\n")
>
> Enter 'a', 'q', or 'f': q
> Finished
>
> now how can i have the input be JUST the "e" and not the newline "\n"?
> thanks for anyhelp, this problem has given me much fuss.
>
> russ
>
>
> --
> www.russelldsmith.freeservers.com
>
>
>

==^================================================================
EASY UNSUBSCRIBE click here: http://topica.com/u/?bUrGcz.bU68iF
Or send an email To: gameprogrammer-unsubscribe@topica.com
This email was sent to: list@pendleton.com

T O P I C A  -- Learn More. Surf Less.
Newsletters, Tips and Discussions on Topics You Choose.
http://www.topica.com/partner/tag01
==^================================================================