fscanf bug in TC (BC) C++ 2.0

Andreas Krey krey at i30fs1.NoSubdomain.NoDomain
Thu Apr 18 00:31:39 AEST 1991


In article <26502 at hydra.gatech.EDU>, jt2 at prism.gatech.EDU (TROSTEL,JOHN M) writes:
|> In article <1991Apr16.141117.5065 at odin.diku.dk> juul at diku.dk (Anders Juul Munch) writes:
|> >cn at 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 at 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 at ira.uka.de



More information about the Comp.lang.c mailing list