Possible Duplicate:
How to pass an array of struct using pointer in c/c++?
I have an array of structures and need to pass a pointer to the array to a function.
I get these compile warnings and it crashes at runtime:
test.c:35:5: warning: passing argument 1 of ‘displayArray’ from incompatible pointer type
test.c:20:6: note: expected‘struct tagdata **’
but argument is of type‘struct tagdata (*)[10]’
typedef struct tagdata{
char lastName[20];
char firstName[20];
int age;
} PERSON[10], *PPERSON[];
int genNumber();
void displayArray(PPERSON pPerson);
int main(){
PERSON personDetails;
int i;
char buf[20];
for (i = 0; i < 10; i++){
sprintf(buf, "Charlie%d", i);
strcpy(personDetails[i].firstName, buf);
sprintf(buf, "Brown - %d", i);
strcpy(personDetails[i].lastName, buf);
personDetails[i].age = genNumber();
}
displayArray(&personDetails);
exit(0);
}
void displayArray(PPERSON pPerson){
int i = 0;
while (i < 10){
printf("Last Name First Name Age\n");
printf("%s %s %d\n",
pPerson[i]->lastName,
pPerson[i]->lastName,
pPerson[i]->age);
i++;
}
}
int genNumber(){
int n;
n=random();
return(n);
}