delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/17/18:45:28

From: "John M. Aldrich" <fighteer AT cs DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: djgpp
Date: Mon, 17 Aug 1998 18:35:34 -0400
Organization: Two pounds of chaos and a pinch of salt.
Lines: 44
Message-ID: <35D8B036.CBF84838@cs.net>
References: <3 DOT 0 DOT 2 DOT 32 DOT 19980817130828 DOT 006a8368 AT 38 DOT 160 DOT 162 DOT 2>
NNTP-Posting-Host: ppp232.cs.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

> I have a very simple C program that I was able to compile and execute using
> a different compiler.  I was able to compile and execute the program with
> gcc.  However, when the program reached the point where it attempts to read
> a string from the keyboard using scanf, there is a problem.  The program
> doesn't seem to register the <CR>.  I can enter in characters and hit ENTER
> as much as I want, but it just gets stuck right there.
> 
> I am a very inexperienced C programmer, but seeing that the program worked
> with a different compiler, I don't think that the problem is the program
> itself.  Can you help?

Since your program compiles and runs, the problem is not likely to be in
the environment (which looks fine to me).  Please post a sample of the
code that fails to work as you expect, or the entire program if it's not
too long.  In the meantime, look in the DJGPP Frequently Asked Questions
list which has answers for many commonly encountered porting problems,
and try out a couple of ideas.

Sometimes problems with text input can be caused by assumptions about
the way input functions work that are only valid on certain compilers. 
If you are trying to mix functions like getch(), gotoxy(), cgets(),
etc., with functions like printf() and scanf(), you may run into
problems because conio and stdio are not really compatible with each
other.

One common problem with scanf() is that incorrect input from previous
calls to scanf() can become "stuck" in the input buffer; for example, if
scanf() tries to read a number but there is a non-digit in the buffer,
it will refuse to read any further and will leave the non-digit
characters there.  If you continue to try to read numbers, scanf() will
never give you any data.  One way to test this is to look for the return
value of scanf() - it indicates the number of items successfully read.

Make sure your program doesn't do any nonstandard tricks with stdin such
as switching it to binary mode or calling fflush(stdin).

hth!

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |     mailto:fighteer AT cs DOT net     |
| Plan:  To find ANYONE willing to |   http://www.cs.net/fighteer/  |
| play Descent 2 on DWANGO!        |       ICQ UIN#:  7406319       |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019