home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16314 < prev    next >
Encoding:
Text File  |  1992-11-10  |  1.1 KB  |  35 lines

  1. Newsgroups: comp.lang.c
  2. 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
  3. From: misar@rbg.informatik.th-darmstadt.de (walter misar)
  4. Subject: Re: void pointer to a struct?
  5. Sender: news@news.th-darmstadt.de (The News System)
  6. Message-ID: <1992Nov11.093732@rbg.informatik.th-darmstadt.de>
  7. Date: Wed, 11 Nov 1992 08:37:32 GMT
  8. References:  <1992Nov10.220944.1810@news.ysu.edu>
  9. Nntp-Posting-Host: rbhp60.rbg.informatik.th-darmstadt.de
  10. Organization: TU Darmstadt
  11. Lines: 22
  12.  
  13. In article <1992Nov10.220944.1810@news.ysu.edu>, ae007@yfn.ysu.edu (Daniel Newcombe) writes:
  14. > Hi, I have a struct te { int i; char c}
  15. > In the main part of the program I have the variable r declared
  16. > as type te.  I also have j as type char.  I then have
  17. > void *o   in there.  At first I have o point to j and do
  18. > a printf("%c",*(char *)o) and this works.  How would I use
  19. > o to point to r, and be able to print the c field?
  20. > Thanks...
  21. >  -Dan
  22.  
  23. Huch ???
  24.  
  25. printf("%c",((te *)(o=(void *)&r))->c);
  26.  
  27. should work, or a bit more readable:
  28.  
  29. o=(void *)&r;
  30. printf("%c",((te *)o)->c);
  31.  
  32. Walter
  33.  
  34.