I am trying to create a struct array named Record. For this, I used the code below:
typedef struct{
int studentID;
char studentName[20];
}STUDENT;
typedef struct{
STUDENT item;
struct RECORD *link;
}RECORD;
void initializeTable(RECORD *, int);
int main(){
int i;
int m;
RECORD *hashTable;
printf("Table Size: "); scanf("%d", &m);
initializeTable(hashTable, m);
}
void initializeTable(RECORD *hashTable, int m){
int i;
hashTable = (RECORD *)malloc(m * sizeof(RECORD));
for(i=0; i<m; i++){
hashTable[i] = NULL;
}
}
I got this error:
incompatible types when assigning to type ‘RECORD {aka struct <anonymous>}’ from type ‘void *’
hashTable[i] = NULL;
Where am I doing wrong?
hashTable[i]isRECORD, not pointer. E.g Change to likehashTable[i] = (RECORD){ .link = NULL};NULLto a structure has no meaning. Initialize each member. Also In your approach you can not actually set the initial value tohashTableofmain.linkfield. It has typestruct RECORD, but that has never been defined. When you try to access it, you will likely have trouble.hashTablewill be lost when returning frominitializeTable.