Ciao, ho degli esercizi da fare sulle liste concatenate ma mi sono bloccata al primo, cioè "crea nodo". Il codice è:
Come errore il compilatore mi da questocodice:#include <stdio.h> #include <string.h> #define N 10; typedef enum{FALSE, TRUE} bool; typedef enum{ERROR, OK} status; typedef struct _nodo* lista; lista crea_nodo(char* s); struct _nodo { char* str; //stringa == il nostro dato lista nxt; //puntatore al prossimo elemento } nodo; menu() { system("clear"); printf("\n0 - Uscita"); printf("\n1 - crea_nodo"); printf("\nInserisci una risposta: "); int risp; scanf("%d", &risp); getchar(); return risp; } main() { lista l; char stringa[N]; while(1) { int scelta = menu(); switch(scelta) { case 0: exit(0); case 1: printf("\nCreo un nodo. Inserisci una stringa: \n"); scanf("%s", stringa); crea_nodo(stringa); break; default: exit(0); } } } /* Restituisce un nodo inizializzato con s. */ lista crea_nodo(char* s) { lista result = (lista)malloc(sizeof(nodo)); strcpy(result->str, s); result->nxt = NULL; return result; }
Cosa sbaglio?codice:lista.c: In function ‘main’: lista.c:47:15: error: expected ‘]’ before ‘;’ token lista.c:53:6: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default] lista.c:56:18: error: ‘stringa’ undeclared (first use in this function) lista.c:56:18: note: each undeclared identifier is reported only once for each function it appears in lista.c: In function ‘crea_nodo’: lista.c:114:24: warning: incompatible implicit declaration of built-in function ‘malloc’ [enabled by default]

Rispondi quotando