[comp.sys.mac.programmer] ThinkC scanf

u2zj@vax5.cit.cornell.edu (Stanton Loh) (03/18/91)

In article <1991Mar17.230413.1917@leland.Stanford.EDU>,
noa@leland.Stanford.EDU (Noa More) writes:
> Sender:Noa Rensing
>
> I recently bought a Mac IIsi (with a math co-processor) and got
> Think C 4.00 for it at the educational price. Previously I have
> used Microsoft QuickC and C6.0 and TurboC on DOS machines and
> several different Unix C compilers. I was extremely disappointed
> with the programming enviroment offered by Think C, and I was
> wondering if anyone had any suggestions:
>
> 1. (The most serious) If I use scanf() with floats, the numbers I
> get from the input are completely unrelated to the input, as in:
>

Rebuild the ANSI library, commenting out the #define _NOFLOATING_
statement in ansi_config.h.

-Stanton Loh
u2zj@vax5.cit.cornell.edu.

wirehead@oxy.edu (David J. Harr) (03/18/91)

You might try adding the line
#include <math.h>
to your program. It will do wonders for the accuracy of your sin/cos calls.

David Harr -- wirehead@oxy.edu

"I think happiness is being famous for your financial ability to indulge in
 every kind of excess...The part about being famous I would like best is
 crushing people who get in your way." -- Calvin, "Calvin & Hobbes"
fnordfnordfnordfnordfnordfnordfnordfnordfnordfnordfnordfnordfnordfnordfnord

wirehead@oxy.edu (David J. Harr) (03/18/91)

In response to a poster's question about how to get fscanf to work with
floats under Think C, I posted some drivel about math.h and sin and cos
calls. Please ignore all the white noise, I completely misunderstood what
the poster was asking and shot my mouth off before I had a chance to
really consider what he was talking about. My only excuse is that it was
a
 Monday morning, early, after a Sunday night, late. Please excuse the waste
of bandwidth, but I didn't want everyone thinking I was a drooling cretin
(I don't drool :-)

David Harr

"I think happiness is being famous for your financial ability to indulge in
  every kind of excess...The part about being famous I would like best is
  crushing people who get in your way." -- Calvin, "Calvin & Hobbes"

guido@cwi.nl (Guido van Rossum) (03/18/91)

noa@leland.Stanford.EDU (Noa More) writes:

>1. (The most serious) If I use scanf() with floats, the numbers I
>get from the input are completely unrelated to the input [...]

This sounds like the bug in scanf in 4.00, which is fixed in 4.02.  A
free upgrade from 4.00 to 4.02 can be uploaded from SUMEX.

>2. Can the console window be resized?

Although there is no resize icon, the console window does resize when
you grab it in its bottom right corner.

>3. I very much miss both i/o redirection (<<,>>)

There used to be a main program which you could compile and link with
your program (renaming your own main to _main), which prompted for
arguments and also understood < and > redirection.  It is a little
primitive, but may help you get used to the new environment.  I
suppose it is still provided.

> and context sensitive help

Sorry, can't help you with that one.  The Think people more or less
assume you are a seasoned C programmer, or are using some textbook to
learn C.

--Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
"This is an ex-parrot"

thornley@cs.umn.edu (David H. Thornley) (03/22/91)

In article <3165@charon.cwi.nl> guido@cwi.nl (Guido van Rossum) writes:
>noa@leland.Stanford.EDU (Noa More) writes:
>
>>3. I very much miss both i/o redirection (<<,>>)
>
>There used to be a main program which you could compile and link with
>your program (renaming your own main to _main), which prompted for
>arguments and also understood < and > redirection.  It is a little
>primitive, but may help you get used to the new environment.  I
>suppose it is still provided.
>
No, they changed it somewhere between 2.11 and 4.0.  In 4.0, what
you have to do is use the "ccommand" function documented in the
console part of the Standard Libraries Reference.  This allows you
to do stdin and stdout redirection and command-line arguments.

IMHO, they could have made it easier to find, considering how
important this is for compatibility and the fact that this is
the standard way to print your output rather than take notes as
it scrolls past, but it's there and it works (once you dig through
most of the documentation looking for it).

BTW, the scanf() bug also affects strtod() and atof(), which call
it.  I got my update from the Symantec bulletin board at (408)-
973-9598, it's available in compactor format (compactor is also
available).  It uses ?modem formats and maybe a few others.

DHT

phils@chaos.cs.brandeis.edu (Phil Shapiro) (03/22/91)

In article <3165@charon.cwi.nl> guido@cwi.nl (Guido van Rossum) writes:
   noa@leland.Stanford.EDU (Noa More) writes:

   >1. (The most serious) If I use scanf() with floats, the numbers I
   >get from the input are completely unrelated to the input [...]

   This sounds like the bug in scanf in 4.00, which is fixed in 4.02.  A
   free upgrade from 4.00 to 4.02 can be uploaded from SUMEX.

Right!  This is bug that's fixed in the 4.02 patch.

   >2. Can the console window be resized?

   Although there is no resize icon, the console window does resize when
   you grab it in its bottom right corner.

Yes.  Also, you can resize the console before it appears on the screen
by using the structure "console_options".  Check out p. 167 of the Std.
Lib. Ref.

   >3. I very much miss both i/o redirection (<<,>>)

   There used to be a main program which you could compile and link with
   your program (renaming your own main to _main), which prompted for
   arguments and also understood < and > redirection.

This was the old, v3.0 way of doing things.  The new, v4.0 way is to
use the function ccommand().  It no longer parses < and >, but it
should do more or less what you want.  It's described on p. 171 of the
Std. Lib. Ref.

	-phil
----
   Phil Shapiro                           Technical Support Analyst
   Language Products Group                     Symantec Corporation
		Internet: phils@chaos.cs.brandeis.edu

t_hallam@fennel.cc.uwa.oz.au (04/30/91)

I just found a bug with ThinkC's scanf(). 

float number;

void main()
{
  scanf("%lf",number);
}

put 0.03 and you get 0.3 for number.  Seems that it skips the leading 0
even when they are after a decimal point.

I gather that there is a patch for several bugs in scanf().  If someone has
a copy could they please post it to me.


Thanks in advance
T Hallam

guido@cwi.nl (Guido van Rossum) (05/06/91)

This is probably in the FAQ, but here goes anyway.  Think C 4.0 has a
bug in scanf for floating point numbers.  You also get it with atof()
and strtod().  An upgrade to 4.02 which fixes this bug (and many more
that aren't so serious) is freely available from several sources; I
got it from SUMEX.

--Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
"Nobody expects the Spanish Inquisition"