Scusate, ma è da poco che sto imparando il linguaggio C. Non riesco proprio a capire questo problema, dunque ho una lista, con due campi informazione ed un puntatore,
nel main assegno alla lista determinati valori, attraverso la funzione NewNotifiy. Questa funzione, se la lista è vuota la riempie con i dati passategli per argomento,altrimenti scorre la lista fino alla fine e aggiunge poi i nuovi dati.
Il problema è quanto tento di stampare i valori della lista. Il programma mi si blocca e mi dà errore.
codice:#include <stdio.h> #include <stdlib.h> struct _NOTIFIES{long event;long notify;struct _NOTIFIES* pointer;}; typedef struct _NOTIFIES* NOTIFIES; NOTIFIES NewNotify(NOTIFIES notifies,long event, long notify); int main() { static NOTIFIES n; n=NewNotify(n,7,8); n=NewNotify(n,9,80); printf("primi valori inseriti: %d %d \n",n->event,n->notify); n=n->pointer; printf("altri valori inseriti: %d %d \n",n->event,n->notify); return 0; } NOTIFIES NewNotify(NOTIFIES notifies,long event, long notify) { NOTIFIES cursor; if(notifies==NULL) { notifies=(NOTIFIES)malloc(sizeof(struct _NOTIFIES)); if(notifies!=NULL) { notifies->event=event; notifies->notify=notify; notifies->pointer=NULL; } } else { cursor=notifies; while(cursor!=NULL){cursor=cursor->pointer;} cursor=(NOTIFIES)malloc(sizeof(struct _NOTIFIES)); if(cursor!=NULL) { cursor->event=event; cursor->notify=notify; cursor->pointer=NULL; notifies=notifies->pointer; } } return notifies; }


Rispondi quotando