array of pointers to a structure

Discussion in 'C Programming' started by jof, Aug 22, 2004.

  1. jof

    jof Guest

    struct name
    {
    char ch;
    } *ptr1,*ptr2;

    If this is my structure and if i need to store the address of the pointers
    ptr1 and ptr2 in an array say "del"..how do i do it?

    is it right if:
    struct name
    {
    char ch;
    }*ptr1,*ptr2,*del[5];

    and in the main:

    del[0]=ptr1;

    giving me error--it says teh subscripted value is neither an array nor a
    pointer!!!
    jof, Aug 22, 2004
    #1
    1. Advertising

  2. jof

    -berlin.de Guest

    jof <> wrote:
    > struct name
    > {
    > char ch;
    > } *ptr1,*ptr2;


    > If this is my structure and if i need to store the address of the pointers
    > ptr1 and ptr2 in an array say "del"..how do i do it?


    > is it right if:
    > struct name
    > {
    > char ch;
    > }*ptr1,*ptr2,*del[5];


    > and in the main:


    > del[0]=ptr1;


    > giving me error--it says teh subscripted value is neither an array nor a
    > pointer!!!


    Looks rather fine and e.g.

    #include <stdio.h>
    #include <stdlib.h>

    int main( void )
    {
    struct name {
    char c;
    } *ptr1, *ptr2, *del[ 2 ];

    del[ 0 ] = ptr1;
    del[ 1 ] = ptr2;

    return EXIT_SUCCESS;
    }

    compiles without problems. The error message you get makes it rather
    look like 'del' isn't what you assume it to be. Did you for example
    define the stucture pointers and the 'del' array of pointers as
    global variables and have another variable, accidentally also called
    'del', defined locally within the function?

    Regards, Jens
    --
    \ Jens Thoms Toerring ___ -berlin.de
    \__________________________ http://www.toerring.de
    -berlin.de, Aug 22, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter B. Steiger

    Can a static array contain a dynamic array of pointers?

    Peter B. Steiger, Apr 19, 2004, in forum: C Programming
    Replies:
    8
    Views:
    2,083
    Dave Thompson
    Apr 26, 2004
  2. Excluded_Middle

    Pointers to structure and array of structure.

    Excluded_Middle, Oct 24, 2004, in forum: C Programming
    Replies:
    4
    Views:
    739
    Martin Ambuhl
    Oct 26, 2004
  3. Sean
    Replies:
    2
    Views:
    631
    loufoque
    Sep 24, 2006
  4. Piotrek

    pointers and array of pointers

    Piotrek, Apr 2, 2007, in forum: C Programming
    Replies:
    8
    Views:
    324
    Chris Torek
    Apr 6, 2007
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    657
Loading...

Share This Page