CompuServe Messages

#MAllocate help

    01-Dec-94 05:07:39
Sb: #44417-#MAllocate help
Fm: Theo Klaassen 75152,2572
To: Henry Williams 73527,1446
Hello Henry, like I see your Programm, there is the bug in the while-loop. Because you only do have a pointer on a structure and not a vektor of pointers on that structure. Even you can't copy all the datas at once into a structure, you have to do it for each element in the structure. example : struct record *array[VALUE]; … while( n==1 ) { /* this is only for example */ fgets( name, 256, in ): fgets( family, 256, int ); strcpy(array[n]->name, name ); array[n]->family = atol( family ); …. n++; /* but I am not sure, if it works with the allocated memory */ } And finaly how I do understand your Programm, you want to have a couple of entries, which can be accssed by the arraynumber. But that is not the classical way how to manage that problem. ( see K&R The C Programming Language Chapter 6.3 and 6.4 ). I would use that kind of structure : struct record { struct record *succ; struct record *pred; char name[36]; int family; int nummer; } And then build a list. |======== | |=========| |=========| |1st record | ——> | 2nd record| ——> ….. —–> |nth record | | ========| <—– |========= | <—– <—– |=========|