off topic: Doubt about gcc 3.3.3 and ( getchar() or scanf(%s) )?

Rob Saul wyrd at triskelion-nova.com
Tue Oct 12 20:07:33 UTC 2004


On Oct 12, 2004, at 12:44 PM, Vinicius wrote:

> Hello,
>
> the following code does not work:

it works, just not how you expect it to. ;)

> "
> ...
> void main(void)
> {
>   char option;
>
>   printf("Choose an option: ");
>
>   option = toupper(getchar());
>
>   printf("Chosse another option: ");
>
>   scanf("%c", &option);
>
>   ...
>
>
> It shows "Choose an option: Choose another option ". Why?
> Whether I put two lines "fflush(stdin)" before the inputs, the same
> above occurs.

fflush only flushes output, not input.  see what happens if you put
a call to getchar() before the call to scanf().


>
> P.S.: Where is the best place to put this question, pĺease?

comp.lang.c maybe?





More information about the fedora-list mailing list