Article View: comp.sys.ibm.pc
Article #42914Re: scanf problem in TC v2.01.
From: Marc Schroeder
Date: Thu, 22 Feb 1990 15:36
Date: Thu, 22 Feb 1990 15:36
48 lines
1931 bytes
1931 bytes
I used to have trouble with this as well.. When using the atof() function,
the program would COMPILE and LINK fine, but it would give me a run-time
error (saying: "Scanf: floating point format not linked in", or something
along those lines).
There IS a way around this. You don't even have to use atof() if you don't
want to (I just gave up on it). You can use sscanf() instead (atof() probably
just calls sscanf() anyways)..
To convert a STRING to a FLOAT, use the following format:
#include <stdio.h>
.
.
char *string;
float value;
.
.
sscanf(string, "%f", &value);
To convert a STRING to a DOUBLE, use the following format:
#include <stdio.h>
.
.
char *string;
double value;
.
.
sscanf(string, "%lf", &value);
After each call, string will remain unchanged, and value will contain
the appropriate floating point number.
Note that sscanf() returns an integer value (I believe it's the number
of 'fields' successfully read in).
/\ _ _ \ iNet/Envoy : m.schroeder (org. id = kort)
( / \/ \ / \ e-mail : marc@cpsc.UCalgary.CA
/ / / / \ ms@flip.cpsc.UCalgary.CA
/ / / (_/____/ Fidonet : Marc Schroeder @ 1:134/47
\__/
Marc A. Schroeder * 1st year computer science
University of Calgary
Technical Details
Message-ID:
<2524@cs-spool.calgary.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!alberta!calgary!marc@cpsc.UCalgary.CAReferences:
<204@sdscal.UUCP> <13317@cbnewsd.ATT.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!alberta!calgary!marc@cpsc.UCalgary.CA From: marc@cpsc.UCalgary.CA (Marc Schroeder) Newsgroups: comp.sys.ibm.pc Subject: Re: scanf problem in TC v2.01. Message-ID: <2524@cs-spool.calgary.UUCP> Date: 22 Feb 90 15:36:58 GMT References: <204@sdscal.UUCP> <13317@cbnewsd.ATT.COM> Sender: news@calgary.UUCP Organization: U. of Calgary, Calgary, Alberta, Canada Lines: 48