Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!sunybcs!boulder!hao!oddjob!gargoyle!ihnp4!inuxc!iuvax!pur-ee!uiucdcs!uxc.cso.uiuc.edu!osiris.cso.uiuc.edu!leather From: leather@osiris.cso.uiuc.edu Newsgroups: comp.lang.c Subject: Re: Need help with structure pointers Message-ID: <8900002@osiris.cso.uiuc.edu> Date: Tue, 13-Oct-87 02:07:00 EDT Article-I.D.: osiris.8900002 Posted: Tue Oct 13 02:07:00 1987 Date-Received: Fri, 16-Oct-87 01:12:41 EDT References: <1778@killer.UUCP> Lines: 58 Nf-ID: #R:killer.UUCP:1778:osiris.cso.uiuc.edu:8900002:000:1616 Nf-From: osiris.cso.uiuc.edu!leather Oct 13 01:07:00 1987 > /* Written 11:39 pm Oct 9, 1987 by tad@killer.UUCP > /* ---------- "Need help with structure pointers" ---------- */ > I've never bothered to get a complete grasp over structures before, and > now it is hurting me. Could someone please tell me the proper way to > accomplish the following ugliness? > > pgrogram deleted for ugliness ... |-) > A very important distinction to remember is the difference between: - the structure member operator "." and - the structure pointer operator "->" The member operator works with the name of a structure: x.s = 'X'; The pointer operator works with the pointer to a structure: sp->s = 'X'; You must also be very careful of how you de-reference your pointers (ie. how you access the data for which you have the pointer). *++(stuff->s) = 'X'; Personally, I try not to mix the two operations; but, to each his own. "The C Programming Language" by Brian W. Kernighan & Dennis M. Ritchie treats the subject in depth. Get a copy and read it (Chapter 6). UNTIL THEN - TRY THIS: (I only made it work; making it aesthetically pleasing is a matter of taste &/or programming style, which I choose not to dig into here) struct X {char *s; int a, b; }; main() {struct X x; struct X *sp; char max[25]; sp = &x; sp->s = max; strcpy(x.s, "Some Stuff"); fun(&x); } fun(stuff) struct X *stuff; { *++(stuff->s) = 'X'; printf("%s\n", stuff->s); /* I want this to print "Xme Stuff" */ } Good Luck - Dave L.