Originally Posted by
camel-man
The second getchar is picking up the newline character left in the buffer after the first getchar().
For example you enter in
- "A\n"
first getchar grabs the 'A' then the second getchar grabs the '\n' (this is from hitting the enter key)
There is a neat little trick where you can use scanf(" %c",&ch);
notice the space BEFORE the % sign. This will tell scanf to ignore any whitespace (includes newlines).
OK i know that getchar() take a second order when i press enter , so how i prevent this i don't want this to happen.
then ,notice this code
Code:
#include<stdio.h>
void main (){
int i;
char arr[50];
printf("put a number\n");
scanf("%d\n", &i);
printf("%d\n",i);
printf("put a txt\n");
gets(arr);
puts(arr);
}
it will accept digits and skips the gets() function.