C
Chandrashekar Tippur
All,
I need to initialize an array of structures but I don't know how may
elements are there. I tried to malloc the array but I am not sure how
to initialize them.
Snippet:
struct myarray{
int conf;
char * var;
};
int main(int args, char * argv[]){
struct myarray *MYARRAY[]= malloc(sizeof(struct myarray) *
30);
MYARRAY={{1,"x"}, {2,"y"} ...... }; // How do I initialize
this?
}
This comes out with segmentation fault. How do I do this?
- Shekar
I need to initialize an array of structures but I don't know how may
elements are there. I tried to malloc the array but I am not sure how
to initialize them.
Snippet:
struct myarray{
int conf;
char * var;
};
int main(int args, char * argv[]){
struct myarray *MYARRAY[]= malloc(sizeof(struct myarray) *
30);
MYARRAY={{1,"x"}, {2,"y"} ...... }; // How do I initialize
this?
}
This comes out with segmentation fault. How do I do this?
- Shekar