*Liste chaine avec maloc
This commit is contained in:
parent
3b24ed7282
commit
8731d0b4ae
1 changed files with 43 additions and 0 deletions
43
src/nzg_msgList.c
Normal file
43
src/nzg_msgList.c
Normal 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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue