When the following program is run, then line 10 is skipped, and the buffer n[100]
contains '\n'
only. So, the user is not allowed to save any data in n
. Could you please point what's wrong with the codes? This issue does not happen when line 8 is deleted.
#include <stdio.h>
int main(void)
{
char n[100] = "";
char m[100] = "";
char c = '0';
c = fgetc(stdin);
printf("First :");
fgets(n, 30, stdin);
printf("\nSecond :");
fgets(m, 30, stdin);
return 0;
}
My input to fgetc
was 2\n
.