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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!utcsri!torn!csd.unb.ca!io.sun.csd.unb.ca!d0np
  3. From: d0np@io.sun.csd.unb.ca (Godzilla)
  4. Subject: Re: void pointer to a struct?
  5. Message-ID: <1992Nov11.003509.3033@jupiter.sun.csd.unb.ca>
  6. Sender: news@jupiter.sun.csd.unb.ca
  7. Organization: University of New Brunswick
  8. References:  <1992Nov10.220944.1810@news.ysu.edu>
  9. Date: Wed, 11 Nov 1992 00:35:09 GMT
  10. Lines: 29
  11.  
  12.  
  13.  
  14. In article <1992Nov10.220944.1810@news.ysu.edu>, ae007@yfn.ysu.edu (Daniel Newcombe) writes:
  15. |> 
  16. |> Hi, I have a struct te { int i; char c}
  17. |> In the main part of the program I have the variable r declared
  18. |> as type te.  I also have j as type char.  I then have
  19. |> void *o   in there.  At first I have o point to j and do
  20. |> a printf("%c",*(char *)o) and this works.  How would I use
  21. |> o to point to r, and be able to print the c field?
  22. |> Thanks...
  23. |>  -Dan
  24.  
  25. o = (void *)&r;
  26. printf( "%c", ((struct te *)o)->c );
  27.               ^              ^
  28. not sure, if you need the outer brackets, but this should work.
  29.  
  30. |> -- 
  31. |>     -Dan Newcombe
  32. |> Internet Address:  STDN@VM.MARIST.EDU
  33. |> Youngstown Freenet: ae007@yfn.ysu.edu
  34. |> GOAL: To put the world on 3.5" diskettes...  :)
  35.  
  36.  
  37.                     enjoy
  38.                             Mike
  39. d0np@jupiter.sun.csd.unb.ca
  40. d0np@unb.ca
  41.