Article View: comp.sys.mac.programmer.help
Article #22Re: Please help me with Pointers and Structs
From: Bruce Wedding
Date: Wed, 22 Nov 1995 06:57
Date: Wed, 22 Nov 1995 06:57
58 lines
1984 bytes
1984 bytes
surgsw@mizzou1.missouri.edu (Joel Weinstein) wrote:
>I know it's a lot to ask but I would appreciate it if you guys would
>explain pointers and structs things to me.
ftp a copy of Snippets from any Simtel mirror. It has an excellent
pointer tutorial in it by Ted Jenson.
What do you not understand about structs? A struct is merely a
collection of variables that may be handled together in some ways or
addressed individually. It is usually a "natural" way to group things
that have something in common. For example:
struct _car {
short year;
char model[36];
char make[36];
long miles;
};
A struct may contain any valid type including pointers, other structs,
and user defined types. You may also have arrays of structs.
struct _family_assets{
double cash_on_hand;
double savings;
struct _car car;
};
struct _family_assets assets;
To address an element of a struct, use the . operator like this:
assets.cash_on_hand = 10000;
To address a struct within a struct, follow the same logic:
assets.car.year = 1995;
To pass a struct, pass a pointer to it like this:
/* prototype */
void my_func( struct *_family_assets);
/* call */
my_func( &assets );
In my_func, to assign values, you must use the -> operator. Use it
anytime you are using a struct pointer.
/* in my_func */
assets->savings = 25000;
What else do you need to know?
Bruce
Bruce D. Wedding Have Compiler, Will Travel!
Software Demi God
Katy, TX, USA #1
Technical Details
Message-ID:
<48uf2k$nab@gryphon.phoenix.net>Path:
arc1-ca.pugleaf.net!gryphon.phoenix.net!usenetReferences:
<surgsw-2011951847210001@128.206.206.35>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!gryphon.phoenix.net!usenet From: brucew@phoenixnet (Bruce Wedding) Newsgroups: comp.sys.mac.programmer.help,comp.lang.c Subject: Re: Please help me with Pointers and Structs Date: Wed, 22 Nov 1995 06:57:24 GMT Organization: BranPaul Systems Message-ID: <48uf2k$nab@gryphon.phoenix.net> References: <surgsw-2011951847210001@128.206.206.35> NNTP-Posting-Host: dial75.phoenix.net X-Newsreader: Moe's Newsreader