*Liste chaine avec maloc

This commit is contained in:
rivka_zan 2004-02-19 20:44:22 +00:00
parent 3b24ed7282
commit 8731d0b4ae

43
src/nzg_msgList.c Normal file
View file

@ -0,0 +1,43 @@
#include <stdio.h>
#include <stdlib.h>
typedef struct MsgSpaceListElem msgSpaceListElem;
struct MsgSpaceListElem{
void *id;
int ownerpid; //valeur du pid que lon stoke dan la liste
msgSpaceListElem *next; //adresse du prochain elemen de la liste
};
/* ajout dans la liste */
msgSpaceListElem *addBegining( msgSpaceListElem*list,int ownerpid){
msgSpaceListElem *unSpacemsgListElem;
if( (unSpacemsgListElem=(msgSpaceListElem *)malloc(sizeof(msgSpaceListElem) ) )==NULL){
perror("ereur dallocation de memoire");
exit(1);}
unSpacemsgListElem->ownerpid = ownerpid;
return(unSpacemsgListElem);
}
int main(int argc,char **argv){
msgSpaceListElem *ma_liste;
msgSpaceListElem *listMove;
ma_liste=NULL;
ma_liste=addBegining(ma_liste, 3);
ma_liste=addBegining(ma_liste, 6);
ma_liste=addBegining(ma_liste, 5);
for (listMove=ma_liste ;listMove!=NULL ; listMove=listMove->next)
{
printf("valaeur :%d\n",listMove->ownerpid);
}
return(0);
}