hi knutso,
you need to pass a pointer to pointer to LD struct in order to return that to where are you calling it.
so instead of:
> int fetchData(HEAD *HD, LINE *LD){
use
Code:
int fetchData(HEAD *HD, LINE **LD) {
int i = 0;
HD->iNoOfLn = 100; // Fetch header
// Allocate memory
if(!(*LD = malloc(HD->iNoOfLn * sizeof(LINE)))) {
printf("Error allocating memory\n");
exit(0);
}
// Read lines
for(i=0;i<HD->iNoOfLn;i++) {
(*LD)[i].iLnNo = i+1;
sprintf((*LD)[i].achName,"Item no: %03d", i+1);
}
return(0);
}
Code:
...
printf(!fetchData(&HD,&LD) ? "OK\n" : "ERR\n");
...
damyan