Here the code:
Well, the big structure Radio is realy big, is about 230 Byte in a empty state. But it does not matter, is not it? I think there is a problem with a memory reservation for a pointer for this structure.
struct Radio *RadioGruppen[20]; // global
...
...
...
...
void GenerateGroups(int GruppenStaerke, int GruppenIndex, int ZellenNr)
{
int El = 0;
RadioGruppen[GruppenIndex] = malloc(sizeof(RadioGruppen[GruppenIndex])); // on this line happens first time
RadioGruppen[GruppenIndex]->ZelleNr = ZellenNr;
RadioGruppen[GruppenIndex]->Gruppenstaerke = GruppenStaerke;
RadioGruppen[GruppenIndex]->next = NULL;
for(El = 1; El < GruppenStaerke; El++)
{
ZellenNr++;
RadioGruppen[GruppenIndex] = AppendNewElement(RadioGruppen[GruppenIndex],ZellenNr); // in this function i create with malloc
// function new elements and
// append them to the
// RadioGruppen[GruppenIndex],
}
}
...
...
...
the other header file:
struct Radio * AppendNewElement(struct Radio *lst, int ZNr)
{
struct Radio *new_list_item= malloc(sizeof(new_list_item));
struct Radio *cur= lst; /* declare variable for parsing list */
new_list_item->ZelleNr = ZNr;/* assign elem to list item*/
new_list_item->next = NULL;/* thereisno successorto thenewelement*/
if(lst==NULL) /* if list empty*/
{
return new_list_item;/* return new element*/
}
while(cur->next!= NULL)/* otherwise parse list and search for last elem*/
{
cur=cur->next;
}
cur->next=new_list_item; /* append new element to the last element*/
return lst;/* were turn the new list */
}
Thank you for the answer.
Message Edited by Boris1980 on
03-05-2008 08:54 AM