I'm looking for a simple solution to this. I only have one element and could easily turn it into a simple array of long integers but in the future I will have a struct of random data types so instead of me declaring a bunch of separate arrays of random types, I want to pack the data into a struct.
In this code the problem lies with the calling of load()
but I don't know how to solve it. When I use the &
, in front of the struct variable, the compiler reports warning: passing argument 1 of 'load' from incompatible pointer type
.
The output I expect instead of errors or a segmentation fault is:
0= 1
1= 11
What am I doing wrong?
and here's the code:
#include <stdio.h>
#include <stdlib.h>
typedef struct{
long n;
}a;
void load(a** x){
x[0]->n=1;
x[1]->n=11;
}
int main(void){
a** b=malloc(200);
b[0]->n=2;
b[1]->n=2;
load(&b); //trouble starts here
printf("0= %ld\n",b[0]->n);
printf("1= %ld\n",b[1]->n);
free(b);
return 0;
}