[comp.sys.mac.programmer] String to Float conversion woes...

spencer@hydroplane.cis.ohio-state.edu (Stephen N. Spencer) (11/28/89)

(Using THINK C 3.02 on a 1Meg Mac Plus...)

Got an interesting problem.  For an application I'm writing, I need to have
the user enter several floating-point values into a dialog box.  Set up the
dialog box and the code to process events while the dialog box (modal) is
up no sweat.  Now I have to get the floating-point number from the dialog
item.  Here's the problem.  I've done:

	GetDItem(myDialog, ID, &iType, &iHndle, &iBox);
	GetIText(iHndle, &iStr);

where iStr is a Str255 variable.  

I see the "StringToNum" function but that won't do me any good.  Spent most
of last evening trying to convert that Str255 to a C string so I could do
"atof()" but that didn't work either.  And, interestingly enough, I must be
using "PtoCstr()" incorrectly -- set it up just like my calls to "CtoPstr()"
and the compiler complained of my call not matching the prototype.

Any suggestions, folks?  I'd really appreciate it.

-=-
Stephen N. Spencer      |"For a successful technology, reality must take
ACCAD, 1224 Kinnear Rd. | precedence over public relations, for Nature
Columbus OH 43212       | cannot be fooled."     - Richard P. Feynman
spencer@heinlein.cgrg.ohio-state.edu OR spencer@cis.ohio-state.edu

joe@gistdev.gist.com (Joe Brownlee) (11/29/89)

In article <74424@tut.cis.ohio-state.edu> Stephen N. Spencer <spencer@cis.ohio-state.edu> writes:
>(Using THINK C 3.02 on a 1Meg Mac Plus...)
>[...]                                  And, interestingly enough, I must be
>using "PtoCstr()" incorrectly -- set it up just like my calls to "CtoPstr()"
>and the compiler complained of my call not matching the prototype.

You know, I had lots of troubles with trying to use "PtoCstr()" in LSC 3.02,
too.  I #include'd what the manual said, and it always gave me a link error.
I never did solve it, but then, I didn't have to since I am now using a string
library like ANSI C that works on Pascal-style strings.  I tried adding lots
of the canned libraries to my project, but no luck.

Anyone else seen these problems?

~~~~~~~~~~ Joe Brownlee,  Global Information Systems Technology, Inc. ~~~~~~~~~~
         1800 Woodfield Drive, Savoy, Illinois  61874   (217) 352-1165          
          E-mail: joe@gistdev.UUCP  <or>  {uunet,uiucuxc}!gistdev!joe
 The best diplomat I know is a fully activated phaser bank. -- Montgomery Scott 
       Go ahead.  Pay attention to anything that _I_ say.  Start a trend.

spencer@hydroplane.cis.ohio-state.edu (Stephen N. Spencer) (11/29/89)

In article <839@gistdev.gist.com> joe@gistdev.UUCP (Joe Brownlee) writes:
>In article <74424@tut.cis.ohio-state.edu> Stephen N. Spencer <spencer@cis.ohio-state.edu> writes:
>>(Using THINK C 3.02 on a 1Meg Mac Plus...)
>>[...]                                  And, interestingly enough, I must be
>>using "PtoCstr()" incorrectly -- set it up just like my calls to "CtoPstr()"
>>and the compiler complained of my call not matching the prototype.
>
>You know, I had lots of troubles with trying to use "PtoCstr()" in LSC 3.02,
>too.  I #include'd what the manual said, and it always gave me a link error.
>I never did solve it, but then, I didn't have to since I am now using a string
>library like ANSI C that works on Pascal-style strings.  I tried adding lots
>of the canned libraries to my project, but no luck.
>
>Anyone else seen these problems?
>

Thanks to several people on the 'Net, esp. "mm35+@andrew.cmu.edu", I've
solved my problems with converting Str255 to floats.  Basically, what I 
did was:

	GetDItem(dialog, ID, &iType, &iHndle, &iBox);
	GetIText(iHndle, &iStr);

	iStr[iStr[0]+1] = '\0';
	f = (float)atof((char *)&iStr[1]);

Again, thanks.

-=-
Stephen N. Spencer      |"For a successful technology, reality must take
ACCAD, 1224 Kinnear Rd. | precedence over public relations, for Nature
Columbus OH 43212       | cannot be fooled."     - Richard P. Feynman
spencer@heinlein.cgrg.ohio-state.edu OR spencer@cis.ohio-state.edu