I try to use the function "fgets()" to read the input from keyboard. My code is looks like:
char A[2], B[2];
fgets(A, 2, stdin);
fgets(B, 2, stdin);
I found a weird thing if I type a charater in keyboard, then press "enter". I can see the 2nd fgets (fgets(B, 2, stdin);) is skipped. I think it has not been skipped, it is because there is a charater in stdin after I type the charater and press "enter". But I wonder since I only type one character and "enter", where the one extra character comes from?
The reason I guess the problem is an extra charater is because the problem can be fixed thru:
char A[3], B[2];
fgets(A, 3, stdin);
fgets(B, 2, stdin);
if I increase to 3 but still type one character, the 2nd command will not be skipped any more. Someone can help me this?