bigrigdriver
10-24-2002, 01:43 PM
language: c
objective: get user to enter one character from the keyboard, and evaluate the character (determine if it's upper or lower case, digit, whitespace, etc).
int main (void)
{
/*local definitions*/
char local_char;
int doIt;
/*statements*/
do
{
printf ("do you want to enter a character? 1 = y; 0 = n");
scanf("%d", &doIt);
if (doIt == 1)
{
printf("type a character and press enter");
scanf("%c", &local_char);
get_input (&local_char);
} /* end block if */
} while (doIt == 1) /* end do-while */
return 0;
} /* main */
The first scanf works (stops and waits for user to choose to continue or quit).
The second scanf (inside the if block) doesn't stop program execution and wait for user to input a character from the keyboard. Execution skips over the scanf, and goes directly to the function call to analyse the keyboard input, which is supposed to be passed by address to the function get_input.
Question: what would cause gcc to ignore the second scanf?
objective: get user to enter one character from the keyboard, and evaluate the character (determine if it's upper or lower case, digit, whitespace, etc).
int main (void)
{
/*local definitions*/
char local_char;
int doIt;
/*statements*/
do
{
printf ("do you want to enter a character? 1 = y; 0 = n");
scanf("%d", &doIt);
if (doIt == 1)
{
printf("type a character and press enter");
scanf("%c", &local_char);
get_input (&local_char);
} /* end block if */
} while (doIt == 1) /* end do-while */
return 0;
} /* main */
The first scanf works (stops and waits for user to choose to continue or quit).
The second scanf (inside the if block) doesn't stop program execution and wait for user to input a character from the keyboard. Execution skips over the scanf, and goes directly to the function call to analyse the keyboard input, which is supposed to be passed by address to the function get_input.
Question: what would cause gcc to ignore the second scanf?