Mail Archives: djgpp/1999/04/07/16:25:42
DJ Delorie schrieb:
>
> You have two problems.
>
> 1. fflush(stdin) does absolutely nothing in DJGPP (nor should it).
> Using gets() is the right thing to do there.
>
> 2. The *first* scanf doesn't read the whole line - it leaves a bit
> behind, which is read as the first line in your loop. I recommend
> doing something like this:
>
> char buf[100];
> fgets(buf, 100, stdin);
> sscanf(buf, "%d", &z);
>
> Don't use gets because it has no way of stopping you from overflowing
> your buffer.
>
Thank you for your hint, i was using TurboC for a long time, so i didn't
know that.
In TurboC you MUST do fflush(stdin) before you can use gets, because the
buffer must
be empty(How can you empty the buffer in DJGPP?).
P.S.: I made a typing error. I wrote scanf(text[i]), but I wanted to
write
scanf("%s", text[i]).
Greetings,
David
- Raw text -