Using pointers to access something in a struct

This is a discussion on Using pointers to access something in a struct within the C Programming forums, part of the General Programming Boards category; I have a struct, and I have been passed a pointer to it to the function I'm in, how do ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    145

    Using pointers to access something in a struct

    I have a struct, and I have been passed a pointer to it to the function I'm in, how do I then use this pointer to access stuff in the struct?

    Thanks

  2. #2
    Registered User divineleft's Avatar
    Join Date
    Jul 2006
    Posts
    158
    I'm not sure what you're saying, post some source code.

    do you mean with the "->" operator?

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    fooptr->member
    Is the pointer equivalent of
    foo.member

    You can also do
    (*fooptr).member or fooptr[0].member if you want, though the latter is preferred if you really do have a pointer to an array of structures.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  2. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. Replies: 2
    Last Post: 11-28-2003, 10:50 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21