Hello All,
I made a simple code to count the number of 'a' until meet '.'
Below is the code that I programmed.
=============================================================
int i = 0;
char input ='0';
while (input != '.')
{
if (input == 'a')
i++;
printf("Enter your character : ");
input = getchar();
}
printf("number of a : %d", i);
============================================================
Unfortunately, the result is not what I intended.
===========================================================
Enter your character : a
Enter your character : Enter your character : ab
Enter your character : Enter your character : Enter your character : abc
Enter your character : Enter your character : Enter your character : Enter your character : .
number of a : 3
========================================================
I can't understand the reason why "Enter your character" is printed repeatedly.
Please help me.
Thanks,
I made a simple code to count the number of 'a' until meet '.'
Below is the code that I programmed.
=============================================================
int i = 0;
char input ='0';
while (input != '.')
{
if (input == 'a')
i++;
printf("Enter your character : ");
input = getchar();
}
printf("number of a : %d", i);
============================================================
Unfortunately, the result is not what I intended.
===========================================================
Enter your character : a
Enter your character : Enter your character : ab
Enter your character : Enter your character : Enter your character : abc
Enter your character : Enter your character : Enter your character : Enter your character : .
number of a : 3
========================================================
I can't understand the reason why "Enter your character" is printed repeatedly.
Please help me.
Thanks,