chou@cs.washington.edu (Pai Chou) (04/30/91)
I am having a problem with THINK C's scanf for doubles. For example, if I scan in a double like 0.0258, I get back 0.258 -- it seems that the leading zeros are ignored. Is anybody else having the same problem? Does anyone know a fix? I am using version 4.0. Is it fixed in the upgrade? Thanks Pai Chou chou@june.cs.washington.edu
johnc@waikato.ac.nz (05/01/91)
In article <1991Apr30.081412.8116@beaver.cs.washington.edu>, chou@cs.washington.edu (Pai Chou) writes: > I am having a problem with THINK C's scanf for doubles. > For example, if I scan in a double like 0.0258, I get back 0.258 > -- it seems that the leading zeros are ignored. > > Is anybody else having the same problem? Does anyone > know a fix? I am using version 4.0. Is it fixed in > the upgrade? Thanks > > Pai Chou > chou@june.cs.washington.edu I'm having exactly the same problem and was searching this newsgroup for the answer! The only way I can get sensible numbers is to put them into sci form e.g. 0.001 gets read as 0.1 unless you make it 1E-3 which I don't want to have to do. Altering the field specifier in the format string doesn't help at all e.g. "%8lf" for reading a double in a field of 8 (I'm using THINK C v4.0 too) Somebody must know! John Curtis johnc@waikato.ac.nz
pas@unhd.unh.edu (Paul A. Sand) (05/01/91)
In article <1991May1.123600.3571@waikato.ac.nz> johnc@waikato.ac.nz writes: >In article <1991Apr30.081412.8116@beaver.cs.washington.edu>, chou@cs.washington.edu (Pai Chou) writes: >> I am having a problem with THINK C's scanf for doubles. >> [...] >I'm having exactly the same problem and was searching this newsgroup for the >answer! I responded to the original poster via email, but if others are in the same boat: the scanf() bug was fixed in the first upgrade to 4.0 (along with a lot of other stuff). Upgrade to 4.0.2; it's free, and available on many FTP sites and commercial services. ~ -- -- Paul A. Sand | Disclaimer: The opinions expressed -- University of New Hampshire | herein are my own. Duh. -- uunet!unhd!pas | (Jim Showalter) -- pas@unhd.unh.edu |
steve@huxley.huxley.bitstream.com (Steve Stein) (05/01/91)
My scanf works OK. I have upgraded to THINK C 4.0.4 (though if you're not running System 7, I think 4.0.2 is what you should be running). In looking at the scanf.c source, about 60% through the file I see: /* (floating) process each digit */ case -2: if (c>='0' && c<='9') { F.valid = TRUE; if (c!='0' || D.sig[0]) { if (D.sig[0] < sizeof D.sig - 1) D.sig[++D.sig[0]]=c; } if (F.dot) /* moved this from inside the previous block - THINK tech sup */ --D.exp; } Note the "if (F.dot)" moved from inside previous block. This, I presume, was the bug you are seeing. I suggest you find an upgrade to 4.0.2. Call Symantec languages tech support. They are friendly, helpful, and knowledgable. They probably won't give you irresponsible advice like the following: Alternatively, and I don't suggest this unless you know what you are doing, you can hack the scanf source yourself in the ANSI project, remake the project, and reload it into your applications. If you have to ask how exactly this is done, then please don't do it. (PLEASE if you do this, do it on a copy and save the original distribution ANSI and scanf.c.) - Steve Stein
phils@chaos.cs.brandeis.edu (Phil Shapiro) (05/03/91)
In article <1991May1.123600.3571@waikato.ac.nz> johnc@waikato.ac.nz writes: In article <1991Apr30.081412.8116@beaver.cs.washington.edu>, chou@cs.washington.edu (Pai Chou) writes: > I am having a problem with THINK C's scanf for doubles. > For example, if I scan in a double like 0.0258, I get back 0.258 > -- it seems that the leading zeros are ignored. > > Is anybody else having the same problem? Does anyone > know a fix? I am using version 4.0. Is it fixed in > the upgrade? Thanks > > Pai Chou > chou@june.cs.washington.edu I'm having exactly the same problem and was searching this newsgroup for the answer! The answer is: Get the 4.0.2 Think C update. It fixes this bug in the scanf() code, as well as minor bugs in the TCL and in the compiler itself. You can ftp this patch from sumex.stanford.edu (36.44.0.6), under the path /info-mac/lang/think-c-402-update.hqx (or possibly .sit.hqx, I forget). It's a binhex'd stuffit archive. -phil -- Phil Shapiro Technical Support Analyst Language Products Group Symantec Corporation Internet: phils@chaos.cs.brandeis.edu
bitting-douglas@cs.yale.edu (Douglas Bitting) (05/03/91)
In article <1991May1.123600.3571@waikato.ac.nz> johnc@waikato.ac.nz writes: >In article <1991Apr30.081412.8116@beaver.cs.washington.edu>, chou@cs.washington.edu (Pai Chou) writes: >> I am having a problem with THINK C's scanf for doubles. >> For example, if I scan in a double like 0.0258, I get back 0.258 >> -- it seems that the leading zeros are ignored. >> >> Is anybody else having the same problem? Does anyone >> know a fix? I am using version 4.0. Is it fixed in >> the upgrade? Thanks >> >> Pai Chou >> chou@june.cs.washington.edu > >I'm having exactly the same problem and was searching this newsgroup for the >answer! > >The only way I can get sensible numbers is to put them into sci form >e.g. 0.001 gets read as 0.1 unless you make it 1E-3 which I don't want to >have to do. > >Altering the field specifier in the format string doesn't help at all >e.g. "%8lf" for reading a double in a field of 8 > >(I'm using THINK C v4.0 too) > >Somebody must know! There is a rather nasty bug in the scanf code for THINK C v4.0. This has been fixed as far as I know under THINK C 4.0.2 and later. The updater for 4.0.2 is on sumex somewhere I think. Hopefully, this will take care of your problems. >John Curtis >johnc@waikato.ac.nz Doug -- Doug Bitting | "And we know that in all things God works PO Box 3043 Yale Station | for the good of those who love him..." New Haven, CT 06520 | --Romans 8:28 bitting@cs.yale.edu +------------------------------------------