If I enter str1
longer than length 10, the rest of it remains in the buffer and gets entered into my str2
. How to clear the buffer before str2
, so I can input it?
#include <stdio.h>
int main(void)
{
char str1[10];
char str2[10];
fgets(str1,10,stdin);
fgets(str2,10,stdin);
puts(str1);
puts(str2);
return 0;
}