array of pointers to a structure

J

jof

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!!!
 
J

Jens.Toerring

jof said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top