I want to allocate array of structure but I'm getting this error with GCC:
st.c: In function ‘main’:
st.c:20:4: error: incompatible types when assigning to type ‘struct employeeStruct’ from type ‘void *’ *sp=malloc(sizeof(struct productStruct)*n);
And this is my struct and pointer:
struct productStruct
{
unsigned int ID;
unsigned long int serialnumber;
char name[40];
};
struct productStruct *sp;
And after getting n variable from user at main function:(Im getting error for this line)
*sp=malloc(sizeof(struct *productStruct)*n);
I don't know maybe this is type casting error but I could not fix it. Thanks for your attention
sp=malloc(sizeof(struct *productStruct)*n);don't de'reference you'll be OKspis the pointer and*spdereferenced pointer .sp = malloc(sizeof(struct productStruct) * n)sp=malloc(sizeof(*sp)*n);so if type changes themallocremains coherent