home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!utcsri!torn!csd.unb.ca!io.sun.csd.unb.ca!d0np
- From: d0np@io.sun.csd.unb.ca (Godzilla)
- Subject: Re: void pointer to a struct?
- Message-ID: <1992Nov11.003509.3033@jupiter.sun.csd.unb.ca>
- Sender: news@jupiter.sun.csd.unb.ca
- Organization: University of New Brunswick
- References: <1992Nov10.220944.1810@news.ysu.edu>
- Date: Wed, 11 Nov 1992 00:35:09 GMT
- Lines: 29
-
-
-
- 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
-
- o = (void *)&r;
- printf( "%c", ((struct te *)o)->c );
- ^ ^
- not sure, if you need the outer brackets, but this should work.
-
- |> --
- |> -Dan Newcombe
- |> Internet Address: STDN@VM.MARIST.EDU
- |> Youngstown Freenet: ae007@yfn.ysu.edu
- |> GOAL: To put the world on 3.5" diskettes... :)
-
-
- enjoy
- Mike
- d0np@jupiter.sun.csd.unb.ca
- d0np@unb.ca
-