member of a structure that is a stucture member

This is a discussion on member of a structure that is a stucture member within the C Programming forums, part of the General Programming Boards category; I thought I could access member "data" in the "next" node of a linked list with: node->next->data but I seem ...

  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300

    member of a structure that is a stucture member

    I thought I could access member "data" in the "next" node of a linked list with:

    node->next->data

    but I seem to be getting a segfault, could that be the reason?

    Am I wrong?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Obviously, if the next pointer is NULL, you can expect a seg-fault. Other reasons may exist too.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I suppose I should be glad that's the answer.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Regarding accessing the structure member
    By kollurisrinu in forum C Programming
    Replies: 5
    Last Post: 06-18-2008, 05:51 AM
  2. Replies: 5
    Last Post: 02-14-2006, 09:04 AM
  3. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 12:14 PM
  4. structure member initialization
    By ivandn in forum C Programming
    Replies: 4
    Last Post: 10-27-2001, 02:27 PM
  5. structure member values
    By breed in forum C Programming
    Replies: 3
    Last Post: 10-25-2001, 07:20 AM

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