L
Lalatendu Das
Dear friends,
I am getting a problem in the code while interacting with a nested
Do-while loop
It is skipping a scanf () function which it should not. I have written
the whole code below. Please help me in finding why such thing is
happening and what the remedy to it is. Kindly bear with my English.
int
main ()
{
int num1[4] , i = 0 ;
char ch ;
do
{
do
{
printf ("Enter the number in the array \n");
scanf("%d",&num );
i++;
} while (i<=3);
printf("Do u want to refill the array again y/n
\n");
scanf ("%c", &ch); /* This line is skipped, it
is not
prompting to
give input
from keyboard
*/
} while (ch = = 'y') ; /* In gdb 'ch' is
showing the value same as
it has at the time of declaration i.e.
some garbage */
return 0;
}
I know this is very silly question for many of u but still I am in
ambiguity to resolve it . So please send me all possible way of
resolving it. and why such problem occurring. The environment in which
I have done it is gcc-3.2.2, red hat Linux -9 , debugged using gdb .
I am getting a problem in the code while interacting with a nested
Do-while loop
It is skipping a scanf () function which it should not. I have written
the whole code below. Please help me in finding why such thing is
happening and what the remedy to it is. Kindly bear with my English.
int
main ()
{
int num1[4] , i = 0 ;
char ch ;
do
{
do
{
printf ("Enter the number in the array \n");
scanf("%d",&num );
i++;
} while (i<=3);
printf("Do u want to refill the array again y/n
\n");
scanf ("%c", &ch); /* This line is skipped, it
is not
prompting to
give input
from keyboard
*/
} while (ch = = 'y') ; /* In gdb 'ch' is
showing the value same as
it has at the time of declaration i.e.
some garbage */
return 0;
}
I know this is very silly question for many of u but still I am in
ambiguity to resolve it . So please send me all possible way of
resolving it. and why such problem occurring. The environment in which
I have done it is gcc-3.2.2, red hat Linux -9 , debugged using gdb .