home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!mcsun!Germany.EU.net!rrz.uni-koeln.de!unidui!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
- From: misar@rbg.informatik.th-darmstadt.de (walter misar)
- Subject: Re: void pointer to a struct?
- Sender: news@news.th-darmstadt.de (The News System)
- Message-ID: <1992Nov11.093732@rbg.informatik.th-darmstadt.de>
- Date: Wed, 11 Nov 1992 08:37:32 GMT
- References: <1992Nov10.220944.1810@news.ysu.edu>
- Nntp-Posting-Host: rbhp60.rbg.informatik.th-darmstadt.de
- Organization: TU Darmstadt
- Lines: 22
-
- In article <1992Nov10.220944.1810@news.ysu.edu>, 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
-
- Huch ???
-
- printf("%c",((te *)(o=(void *)&r))->c);
-
- should work, or a bit more readable:
-
- o=(void *)&r;
- printf("%c",((te *)o)->c);
-
- Walter
-
-