home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!portal!dfuller
- From: dfuller@portal.hq.videocart.com (Dave Fuller)
- Subject: Re: void pointer to a struct?
- Message-ID: <BxKrEy.7sK@portal.hq.videocart.com>
- Organization: VideOcart Inc.
- X-Newsreader: Tin 1.1 PL3
- References: <1992Nov10.220944.1810@news.ysu.edu>
- Date: Wed, 11 Nov 1992 23:18:33 GMT
- Lines: 36
-
- ae007@yfn.ysu.edu (Daniel Newcombe) writes:
- :
- : Hi, I have a struct te { int i; char c}
- : In the main part of the program I have the variable r declared
- : as type te. I also have j as type char. I then have
- : void *o in there. At first I have o point to j and do
- : a printf("%c",*(char *)o) and this works. How would I use
- : o to point to r, and be able to print the c field?
- : Thanks...
- : -Dan
-
- ---------------------
-
- If r is type te then
- printf("%c", r.c);
- works rather well.
-
- ---------------------
-
- if you want to pass r around then use the pointer to it elsewhere do
-
- o = (void *) &r;
-
- to print out the char element c do
-
- printf("%c", ((struct te*)o)->c);
-
- ---------------------
- pretty messy, huh ?
-
- this could be done MUCH cleaner using another method. But using the types
- and methods that you defined, this works for it.
-
- Dave Fuller
- dfuller@portal.hq.videocart.com
-
-