C
chen_li3
Hi all,
I am new for this forum. I have a question about a for loop in c
language: I try to get 5 characters one by one from the keyboard and
print them out. The for loop repeats 5 times BUT only accept 3
characters(a,b, and c) from keyboard. I wonder if anyone there can
explains why.
Thanks,
Li
#include <stdio.h>
main()
{
int i;
int ch;
for( i = 1; i<= 5; i++ ) {
printf("%d\n",i);
ch= getchar();
putchar(ch);
}
}
output:
1
a
a2
3
b
b4
5
c
c
I am new for this forum. I have a question about a for loop in c
language: I try to get 5 characters one by one from the keyboard and
print them out. The for loop repeats 5 times BUT only accept 3
characters(a,b, and c) from keyboard. I wonder if anyone there can
explains why.
Thanks,
Li
#include <stdio.h>
main()
{
int i;
int ch;
for( i = 1; i<= 5; i++ ) {
printf("%d\n",i);
ch= getchar();
putchar(ch);
}
}
output:
1
a
a2
3
b
b4
5
c
c