| www.delorie.com/archives/browse.cgi | search |
| Message-ID: | <370BB323.E645FC7C@cityweb.de> |
| From: | David Renz <davidprrenz AT cityweb DOT de> |
| X-Mailer: | Mozilla 4.03 [de] (Win95; I) |
| MIME-Version: | 1.0 |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: DJGPP-Problem |
| References: | <37026DF6 DOT BCAA8E59 AT cityweb DOT de> <Pine DOT HPP DOT 3 DOT 95 DOT 990401074240 DOT 16475A-100000 AT hepo DOT cc DOT lut DOT fi> <37090A8C DOT 89F098AA AT cityweb DOT de> <199904052126 DOT RAA09813 AT envy DOT delorie DOT com> |
| Lines: | 31 |
| Date: | Wed, 07 Apr 1999 21:33:55 +0200 |
| NNTP-Posting-Host: | 62.52.155.162 |
| X-Trace: | news1.cityweb.de 923515344 62.52.155.162 (Wed, 07 Apr 1999 22:02:24 MET DST) |
| NNTP-Posting-Date: | Wed, 07 Apr 1999 22:02:24 MET DST |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |