I'm having problems while using gets in C.
...
int main()
{
char test[20], m[20];
int n;
scanf("%d", &n);
while(n)
{
gets(test);
test.kolona = n;
m = decode(test); //some function
printf("%s",m.sif);
putchar('\n');
scanf("%d", &n);
}
}
When I enter a number and press enter, it automatically "prints" a newline, before you input the string. I searched a bit and found that this can be avoided if you put a gets before, like this:
...
scanf("%d", &n);
gets(test)
while(n);
{
gets(test);
...
}
But then it messes up again as the loop continues :(
Is there an elegant solution to this?
sample to fix