Newsgroups: comp.lang.c
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!i30fs1!krey
From: krey@i30fs1.NoSubdomain.NoDomain (Andreas Krey)
Subject: Re: fscanf bug in TC (BC) C++ 2.0
Message-ID: <1991Apr17.143139.20903@ira.uka.de>
Keywords: turbo C++
Sender: krey@i30fs1 (Andreas Krey)
Organization: University of Karlsruhe, FRG
References: <1991Apr14.215819.16486@allgfx.agi.oz> <1991Apr16.141117.5065@odin.diku.dk> <26502@hydra.gatech.EDU>
Distribution: usa
Date: Wed, 17 Apr 1991 14:31:39 GMT
Lines: 78

In article <26502@hydra.gatech.EDU>, jt2@prism.gatech.EDU (TROSTEL,JOHN M) writes:
|> In article <1991Apr16.141117.5065@odin.diku.dk> juul@diku.dk (Anders Juul Munch) writes:
|> >cn@allgfx.agi.oz (Con Neri) writes:
|> >
|> >>Hi netters,
|> >>	I havec been working with a friend developing some code using
|> >>Turbo C++ V1.5 but only writing in standard C. We have been getting an error
|> >>with a particular piece of code, namely
|> >
|> >>	fscanf(fp,"%f", &f);
|> >
|> >>	The runtime error is
|> >
|> >>	scanf: floating point formats not linked
|> >>	Abnormal Program termination.
|> >
|> >>	Can some one shed some light on what this means? 
|> i have found the same problem.  The way I worked around it was to declare
|> a new float variable, say fl_var, and use it to read in my data. See old
|> and new code below:
|> 

Sorry to say so, but that is probably something unrelated. The problem
with 'scanf: floating point formats not linked' is with the libraries.
Most users of printf/scanf don't do floating point and the standard library
code of printf/scanf cannot convert that. You have to set a compiler
flag/option to include the variant capable of float conversion when linking.
(Cannot name the option, I only know this feature from a little C compiler.)

|> OLD CODE:
|> 
|> ...
|> float *f_ptr;
|> ...
|> f_ptr = (float *)calloc(...);
|> ...
|> fscanf(file,"%f",f_ptr);
|> ...
|>       ^----- gives the run time error
|> 
|> NEW CODE:
|> ...
|> float *f_ptr, new_var;
|> ...
|> f_ptr=(float *)calloc(...);
|> ...
|> fscanf(file,"%f",&new_var);
|> f_ptr[i] = new_var;    /* i'm inside a loop here */
|> ....
|>        ^------ this code works!!??
|> 
|> Well, I can't figure it! Nothing else was changed in the program to
|> make it work.  That is it DIDN'T like the address sent to it with
|> using just 'f_ptr' but DID like the address it got with '&new_var'.
|> 
|> Anyone else figure this out more?  Anyone from Borland about to tell
|> us how to fix this?
|> 

This is either a compiler bug (improbable), oder something with
the memory models. new_var is on the stack, f_ptr points to the heap;
looks like far/near pointer trouble. That is, passing the wrong pointer
type.

|> -- 
|> John M. Trostel   ( aka Kayak-Man )                  
|> Georgia Institute of Technology, Atlanta Georgia, 30332
|> uucp: ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!jt2
|> Internet: jt2@prism.gatech.edu

-- 
Andy

-------------------------------------------
Zeit ist Geld. Aber Geld ist keine Zeit.
[Intl: Time is money. But money isn't time.]

To fight xrn stupidity: Andreas Krey, krey@ira.uka.de
