[comp.sys.mac.programmer] Think C programming

mfinegan@uceng.UC.EDU (michael k finegan) (03/31/89)

Does anyone have experience in using Think C to plot on the screen ...
I have compiled a program that plots curves on the screen (not real fast,
uses the unix.h plotting routines, ...) When I tried to cut/copy/print
my handiwork - I found out that Think C doesn't support the edit menu.
I there a solution besides reading the 2 volumes of "Inside the MAC" or
whatever reference Think C manuals give to calling the Pascal routines that
are in ROM?

I have been told that this compiler was used for some very good software,
but it seems very incomplete without documentation of some of the system
specific routines.
				Thanks for anything, even crumbs!
				Mike Finegan
				mfinegan@uceng.uc.edu

juana@dciem.dciem.dnd.ca (Juana Chang) (03/09/90)

Hi. I am new to this news group and I am attempting to learn how to program
in the Macintosh environment with Think C 4.0 which by the way I am also
learning.

And I need HELP !

I am trying to produce a DIALOG BOX with editable items.  And I want to:

1.  Get the text in the dialog item.
2.  Convert the text to an integer.
3.  Edit check this integer.

Therefore, I use:

GetDItem( theDialog, ITEM, &i_itemType, &hdl_item, &rect_item );
/* in order to get the item handle */

GetIText( &hdl_item, str_item );
/* in order to get the text */

This is where I get stuck... 

I print the contents of str_item and get GARBAGE! (pretty little symbols).
I printed the contents out of curiosity and to make sure I was getting the
actual contents that the user places in the editable text box.
I used the DrawString function to print the text onto the screen.

Why am I getting GARBAGE??

Thanks in advance. :-)

rotberg@dms.UUCP (Ed Rotberg) (03/10/90)

From article <2967@dciem.dciem.dnd.ca>, by juana@dciem.dciem.dnd.ca (Juana Chang):
> 
> I am trying to produce a DIALOG BOX with editable items.  And I want to:
> 
> 1.  Get the text in the dialog item.
> 2.  Convert the text to an integer.
> 3.  Edit check this integer.
> 
> Therefore, I use:
> 
> GetDItem( theDialog, ITEM, &i_itemType, &hdl_item, &rect_item );
> /* in order to get the item handle */
> 
> GetIText( &hdl_item, str_item );
> /* in order to get the text */
> 
> This is where I get stuck... 
> 
> I print the contents of str_item and get GARBAGE! (pretty little symbols).
> I printed the contents out of curiosity and to make sure I was getting the
> actual contents that the user places in the editable text box.
> I used the DrawString function to print the text onto the screen.
> 
> Why am I getting GARBAGE??


This is something I do all the time.  Your first problem is that the call to
GetIText is wrong -- it should be 

	GetIText( hdl_item, &str_item );

Note the ampersand (&) before str_item, and none before the handle.  This
may be the problem if for some reason you were not passing the address of
the string, and were passing the address of the handle instead of the handle
itself.  The actual code snippet from my working program is:

GetDItem( Dptr, COUNT_ID, &Itype, &ItmHndl, &box );
GetIText( ItmHndl, &val );
PtCstr(val);

Then use either sscanf or strtod to convert the string to numeric data.

I hope this helps.  Good Luck.

	- Ed Rotberg -

stoms@castor.ncgia.ucsb.edu (David Stoms) (03/11/90)

In article <1007@dms.UUCP> rotberg@dms.UUCP (Ed Rotberg) writes:
>From article <2967@dciem.dciem.dnd.ca>, by juana@dciem.dciem.dnd.ca (Juana Chang):
>> I am trying to produce a DIALOG BOX with editable items.  And I want to:
>> 
>> GetDItem( theDialog, ITEM, &i_itemType, &hdl_item, &rect_item );
>> /* in order to get the item handle */
>> 
>> GetIText( &hdl_item, str_item );
>> /* in order to get the text */
>> 
>> This is where I get stuck... 

I bet every C programmer does this every now and then. Here's the file that
I give to anyone that is having problems with C pointers:

To pass parameters to ROM functions in C you have to be aware of a few things
about Pascal.

If the variable is less than or equal to four bytes long then pass it by value.

Example:
    MoveTo(x, y);

If the variable is longer than four bytes pass it by reference.

Example:
    CopyBits(&srcBitmap, &destBitmap, &srcBounds, &destBounds, srcCopy, nil);

If the variable is declared VAR then pass it by reference no matter what size it
is.

Example:
    GetPort(&AGrafPtr);  (a pointer to a GrafPtr, this is the trickest
                          trap in the ROMs!)

The nice thing about these rules are that there are no exceptions. Too bad
English spelling doesn't work like that.

Another weird thing about C is how you reference a value buried deap down in
handles and pointers. In Pascal you can build from left to right, in C you start
in the middle and work your way out. Examine this example:

DialogPtr    dialog;

                      dialog
          (WindowPeek)dialog
         ((WindowPeek)dialog)->ControlList
      (**((WindowPeek)dialog)->ControlList).contrlOwner
     ((**((WindowPeek)dialog)->ControlList).contrlOwner)->contRgn
  (**((**((WindowPeek)dialog)->ControlList).contrlOwner)->contRgn).rgnBBox

oster@well.sf.ca.us (David Phillip Oster) (03/11/90)

In article <1007@dms.UUCP> rotberg@dms.UUCP (Ed Rotberg) writes:
>From article <2967@dciem.dciem.dnd.ca>, by juana@dciem.dciem.dnd.ca (Juana Chang):
>> GetIText( &hdl_item, str_item );
>> Why am I getting GARBAGE??
>
>	GetIText( hdl_item, &str_item );
>
>Note the ampersand (&) before str_item, and none before the handle.

This entire class of problems can be permanently eliminated from your THINK
C program by re-making your MacHeaders file to include MacProtos.h and 
MacProtos5.h. These two files contain complete prototypes for almost all the
operating system calls, and cause the compiler to give you an error message
when you make this kind of mistake.

I, and others, have previously posted MacProtos.h and MacProtos5.h to
the net, and any good library or users group should have them.

Use them. You'll get done faster.
-- 
-- David Phillip Oster - Note new address. Old one has gone Bye Bye.
-- oster@well.sf.ca.us = {backbone}!well!oster

d88-jwa@nada.kth.se (Jon Watte) (03/12/90)

>Then use either sscanf or strtod to convert the string to numeric data.

And violate the international guidelines.

StringToNum(pstr, &lint);

is the way to go. You don't even have to call PtoCstr before you
do it :-)

h+
-- 
   ---  Stay alert !  -  Trust no one !  -  Keep your laser handy !  ---
             h+@nada.kth.se  ==  h+@proxxi.se  ==  Jon Watte
                    longer .sig available on request

bowman@reed.UUCP (Eric Bowman) (03/12/90)

In article <3115@draken.nada.kth.se> d88-jwa@nada.kth.se (Jon W{tte) writes:
>>Then use either sscanf or strtod to convert the string to numeric data.
>And violate the international guidelines.
>StringToNum(pstr, &lint);

So how do you handle floating point string conversion?
Is the whole SANE struggle the only way?

BoBo
bowman@reed.{bitnet,UUCP,edu}
tektronix!ogccse!reed!bowman

Richard.Diaz@f444.n161.z1.FIDONET.ORG (Richard Diaz) (11/14/90)

Hi my name is Milan Lee and I am learning how to program in Think C.  The
program I want to write requires that use ASCII text file as an input file
and  generate an output file which is in dBase file format.  Could you give 
me any advices on ways that I may approach the problem.  Any suggestion on 
reading material or Think C libraries available through different BBSs would 
greatly be appreciated.

--  
Richard Diaz - via FidoNet node 1:125/777
    UUCP: ...!uunet!hoptoad!fidogate!161!444!Richard.Diaz
INTERNET: Richard.Diaz@f444.n161.z1.FIDONET.ORG

dlandry@ncs.dnd.ca (Dominique Landry) (03/26/91)

 
Hello Think C programmers:
 
I'd like to know the most efficient method of writing a
program in Think C that will recognize wheter or not
a given Macintosh has a Math co-processor; something
similar to EXCEL(R) where if it finds that a 
math co-processor exists then it will use it, otherwise
it will carry on just as none was found.

I will provide a summary of the responses ...
 
Thank you.
                             Dominique
 
Internet: dlandry@ncs.dnd.ca
CompuServe: 71161,1044
 
Bus. Phone: (613)992-3391





 
 

 
 

aep@world.std.com (Andrew E Page) (04/04/91)

  The most efficient(and stable) and stable of determining
the presence of a coprocessor would be through the use of the
_SysEnvirons trap.  Consult IM V-5 for more detailed info.
This routine is provided for just the purpose of determining
the environment.

   If you would like a bit more of a brute force method:
Patch the exception vector for unimplemented instructions and 
execute a floating point instruction right afterwards.  An intereception
of the interupt will indicate the lack of the processor.  I do not
recommend this however.  It just might be more of an interesting method.

-- 
Andrew E. Page (Warrior Poet)   |   Decision and Effort The Archer and Arrow
Concepts Engineering            |     The difference between what we are
CIS:70202,234  BIX:page1        |           and what we want to be.