Thread: Array of Linked Lists Question

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    2

    Array of Linked Lists Question

    Hi,

    I need help implementing an array of linked lists. My code is as follows:

    List structure:

    Code:
    typedef struct L
    {
        char field[50];
        struct L *next;
    } List;
    Then to create the array of Lists, and pass it to another function, I'm using:

    Code:
    List *t[100];
    
    t = listArrayFunction(t);
    With listArrayFunction as:

    Code:
    List **listArrayFunction(List **t)
    {
        printf("/n/nfillList called/n/n");
        return t;
    }
    Now I know I've made a mess with the *'s somewhere, as I get an error "Incompatible types in assignment" on the line t = listArrayFunction(t);

    Could someone help me with this?

    Thanks for your help in advance.
    Last edited by h4m; 01-17-2010 at 01:16 PM.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    **ptr != *ptr[]
    The first one is a pointer to a poiter.
    The 2nd one is an array of pointers.

    Try:
    Code:
    List **listArrayFunction(List *t[])
    [edit] this is not the problem -- see below
    Last edited by MK27; 01-17-2010 at 01:52 PM.
    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

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    2
    Thanks for your help.

    I tried using the correction you mentioned but it seems I've still got something wrong.

    I've tried not returning the array at all and it seems to still update the original array in the main function, so will leave it as it is for now.

    Cheers.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Actually my apologies -- your error was incompatible assignment, which has to do with the =

    And you can pass a pointer array to **arg. Sorry again.

    HOWEVER, you can't return **this to be *that[100], because you cannot really assign anything to an entire array of pointers.
    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. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Replies: 5
    Last Post: 08-01-2007, 06:17 AM
  3. Singly Linked Lists: Clarification Needed
    By jedispy in forum C++ Programming
    Replies: 4
    Last Post: 12-14-2006, 05:30 PM
  4. Linked Lists Question
    By panfilero in forum C Programming
    Replies: 4
    Last Post: 11-22-2005, 01:33 AM
  5. Replies: 2
    Last Post: 01-18-2003, 01:32 AM