off topic: Doubt about gcc 3.3.3 and ( getchar() or scanf(%s) )?
Michael D. Setzer II
mikes at kuentos.guam.net
Wed Oct 13 04:01:56 UTC 2004
It appears that when you use the getchar and type the option and
enter, it returns the character and a LF. I added some things to
yours, and it runs. I type a for the first option, and it prints A for the
first option, and then prints 10 (decimal format) of option2. Then
enter b for the scanf, and it prints out b
Not sure why it is including the LF with the getchar.
void main()
{
char option,option2;
printf("Choose an option:");
option=toupper(getchar());
printf("%c\n",option);
option2=getchar();
printf("Option2 %d\n",option2);
printf("Choose another option:");
scanf("%c",&option);
printf("%c\n",option);
}
On 12 Oct 2004 at 16:44, Vinicius wrote:
From: Vinicius <cviniciusm at terra.com.br>
To: For users of Fedora Core releases <fedora-list at redhat.com>
Date sent: Tue, 12 Oct 2004 16:44:24 -0300
Subject: off topic: Doubt about gcc 3.3.3 and ( getchar() or scanf(%s) )?
Send reply to: For users of Fedora Core releases <fedora-list at redhat.com>
<mailto:fedora-list-request at redhat.com?subject=unsubscribe>
<mailto:fedora-list-request at redhat.com?subject=subscribe>
> Hello,
>
> the following code does not work:
> "
> ...
> 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.
>
> my gcc: "$ gcc --version
> gcc (GCC) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
>
> TIA, Vinicius.
>
> P.S.: Where is the best place to put this question, p ease?
>
> --
> fedora-list mailing list
> fedora-list at redhat.com
> To unsubscribe: http://www.redhat.com/mailman/listinfo/fedora-list
>
+----------------------------------------------------------+
Michael D. Setzer II - Computer Science Instructor
Guam Community College Computer Center
mailto:mikes at kuentos.guam.net
http://www.guam.net/home/mikes
Guam - Where America's Day Begins
+----------------------------------------------------------+
http://setiathome.berkeley.edu
Number of Seti Units Returned: 14,509
Processing time: 29 years, 63 days, 6 hours, 48 minutes
(Total Hours: 255,559)
More information about the fedora-list
mailing list