Why do fgets reads my first input in scanf? [duplicate]
Why do fgets reads my first input in scanf? [duplicate]
This question already has an answer here:
So, when i execute my program it reads one less value than it should, and I think the problem is with the scanf/fgets, but i dont know hot to work it out. Help?
int main(){
int n;
char s[200];
scanf("%i", &n);
for (int i = 0; i<n+1; i++)
{
if (i==0)
{
continue;
} else if (i >=1) {
fgets(s, 200, stdin);
first(s);
second(s);
third(s);
puts(s);
}
}
return 0;
}
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Oh cool, another duplicate.
– melpomene
Jul 2 at 1:28
Likely because scanf() is leaving a newline character in the input buffer.
– Stephen Docy
Jul 2 at 1:28
what's your sample input?
– Stan
Jul 2 at 1:28