Date: Mon, 5 Apr 1999 17:26:22 -0400 Message-Id: <199904052126.RAA09813@envy.delorie.com> From: DJ Delorie To: djgpp AT delorie DOT com In-reply-to: <37090A8C.89F098AA@cityweb.de> (message from David Renz on Mon, 05 Apr 1999 21:10:04 +0200) Subject: Re: DJGPP-Problem References: <37026DF6 DOT BCAA8E59 AT cityweb DOT de> <37090A8C DOT 89F098AA AT cityweb DOT de> Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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. > >> ... > >> scanf ("%d", &z); > >> > >> printf ("Text:\n"); > >> > >> for (i=0;i >> > >> { > >> > >> fflush(stdin); /* i quess here's your problem */ > >> > >> gets(text[i]); > >> > >> l[i]=strlen(text[i]); > >> > >> } > >> ... > >> When I compile it with DJGPP and it should read n(z=n) Lines it only > >> reads n-1 lines. But when I compile it > >> with TurboC it runs correctly. Does someone know where there is a bug? > > > > As i recall, you can't fflush _stdin_ stream, only _stdout_ stream. This > > may cause your problem and irregularities between those two compilers you > > used. > > > No, that can't be the problem, when I leave out the fflush(stdin), it's > still wrong. > But when I replace the gets(text[i]) by scanf(text[i]) it runs > correctly. But with > scanf you can only read words but no sentences(several words with > blanks). Can someone help?