I’m attempting to assign values to my integer array within a structure. I wrote a small test program to demonstrate what I am trying to achieve.
typedef struct{
int *alpha;
int *beta;
} data_t;
int main(int argc, char **argv){
int i=0;
data_t data;
for (i=0; i<100; i++){
data.alpha[i] = i;
data.beta[i] = i*i;
}
for (i=0; data.alpha[i]; i++){
printf("Alpha = %d.\nBeta = %d.\n", data.alpha[i], data.beta[i]);
}
return 0;
}
gdb tells me that the problem is in “data.alpha[i]=i”, but I’m not sure how to assign this value correctly. Thanks for any help.
You don’t have any integer arrays, just two uninitialized pointers.
Try