Vinicius wrote:
> Hello,
>
> the following code does not work:
> "
> ...
> void main(void)
Yep, this could be one reason.
The main() function returns int. Always.
Anything else may lead to undefined behavior.
> {
> 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?
Because you typed in the code instead of pasting it.
I show:
Choose an option: Chosse another option:
This depends on your operating system and how it handles
input and output to the user. Read the C language FAQ
below for more information.
> Whether I put two lines "fflush(stdin)" before the inputs, the same
> above occurs.
The fflush() is not defined for input streams. Again,
another FAQ. You could try flushing the output buffer,
echoing your input character or other platform dependent
solutions. Again, read the FAQ.
>
> my gcc: "$ gcc --version
> gcc (GCC) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
>
> TIA, Vinicius.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book