Article View: comp.sys.ibm.pc
Article #42285Re: scanf problem in TC v2.01.
From: Bill Fenner
Date: Wed, 14 Feb 1990 00:31
Date: Wed, 14 Feb 1990 00:31
56 lines
2753 bytes
2753 bytes
In article <90043.093434CMH117@PSUVM.BITNET> CMH117@psuvm.psu.edu (Charles Hannum) writes:
|In article <25D4D935.3073@maccs.dcss.mcmaster.ca>,
|cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) says:
|> I've had problems with scanf under TCC 2.0. Given something like
|>scanf ("%f", &floatvariable);
|>it will read the keyboard but return garbage (sometimes 0, sometimes NAN,
|>sometimes other values). atof is the cause of this problem; I've
|>tried
|>scanf ("%s", stringvariable); floatvariable = atof (stringvariable);
|>and it has the same problem (not surprising, since scanf calls atof
|>to handle floating point quantities).
|Please, people! If you're going to post bug reports, please give SPECIFIC
|EXAMPLES so us hackers can trace down the offending bug and obliterate it!
|Generalized statements like this ARE NOT HELPFUL!
Um, Charles, that looks pretty specific to me. Or can't you write a little
program? Here, I'll sketch something in for you.
main()
{
float floatvariable;
char stringvariable[50];
scanf("%f",&floatvariable);
printf("got %f\n",floatvariable);
scanf("%s",stringvariable);
floatvariable=atof(stringvariable);
printf("got %f\n",floatvariable);
}
Is that good enough, Charles? Or did you want me to include the output from
the debugger as it runs? (ok, so maybe some sample input and output would be
nice; I don't have TCC so I can't give you any.)
You should have at least tried a program first and seen if you could duplicate
the problem, instead of flaming the guy for not having wasted bandwidth with a
program shell.
(strangely enough, I got funky results from the second one on this machine
(Harris HCX/UX); the first worked fine...)
Script started on Tue Feb 13 19:28:36 1990
(psuhcx)1 /usr3/wcf> test
1.2
got 1.200000
1.4
got 1085485875.000000
(psuhcx)2 /usr3/wcf> exit
exit
script done on Tue Feb 13 19:28:46 1990
Anyway, I'm getting off track. Charles, you were wrong to yell at the guy, it
took me 30 seconds to type in the code around the lines he gave.
--
Bill Fenner wcf@hcx.psu.edu ..!psuvax1!psuhcx!wcf
sysop@hogbbs.fidonet.org (1:129/87 - 814/238-9633) ..!lll-winken!/
Technical Details
Message-ID:
<2097@psuhcx.psu.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!zephyr.ens.tek.com!uw-beaver!mit-eddie!snorkelwacker!usc!brutus.cs.uiuc.edu!psuvax1!psuhcx!wcfReferences:
<90043.093434CMH117@PSUVM.BITNET> <25D8649A.24584@maccs.dcss.mcmaster.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!zephyr.ens.tek.com!uw-beaver!mit-eddie!snorkelwacker!usc!brutus.cs.uiuc.edu!psuvax1!psuhcx!wcf From: wcf@psuhcx.psu.edu (Bill Fenner) Newsgroups: comp.sys.ibm.pc,alt.msdos.programmer Subject: Re: scanf problem in TC v2.01. Message-ID: <2097@psuhcx.psu.edu> Date: 14 Feb 90 00:31:57 GMT References: <90043.093434CMH117@PSUVM.BITNET> <25D8649A.24584@maccs.dcss.mcmaster.ca> Reply-To: wcf@psuhcx.psu.edu (Bill Fenner) Organization: Engineering Computer Lab, Penn State University Lines: 56