buonasera a tutti scusate il disturbo ma ho un problema con questo programma
codice:#include <stdio.h> #include <iostream> #include <string.h> #include <stdlib.h> typedef struct{ char Nome[30]; char Cognome[30]; char Tel[30]; char Indirizzopaginaweb[50]; char Indirizzoemail[50]; } Contatto; struct elemento{ Contatto inf; struct elemento *pun; }; void visualizzaContatto(struct elemento* p){ if (p == NULL){ printf (" # VISUALIZZA CONTATTO #\n"); printf (" Nessun contatto presente\n"); } else { printf (" # VISUALIZZA CONTATTO #\n"); printf (" NOME > %s\n", p->inf.Nome); printf (" COGNOME > %s\n", p->inf.Cognome); printf (" TELEFONO > %s\n", p->inf.Tel); printf (" SITOWEB > %s\n", p->inf.Indirizzopaginaweb); printf (" EMAIL > %s\n", p->inf.Indirizzoemail); } while (p != NULL){ printf (" # VISUALIZZA CONTATTO #\n"); printf (" NOME > %s\n", p->inf.Nome); printf (" COGNOME > %s\n", p->inf.Cognome); printf (" TELEFONO > %s\n", p->inf.Tel); printf (" SITOWEB > %s\n", p->inf.Indirizzopaginaweb); printf (" EMAIL > %s\n", p->inf.Indirizzoemail); p = p->pun; system("PAUSE"); } } struct elemento *aggiungiContatto(struct elemento *p){ printf (" # AGGIUNGI CONTATTO #\n"); char nome[50]; char cognome[50]; char telefono[30]; char email[100]; char sitoweb[200]; Contatto daInserire; struct elemento *punt; punt = (struct elemento *)malloc(sizeof(struct elemento)); p = (struct elemento *)malloc(sizeof(struct elemento)); printf (" NOME > "); scanf ("%s", nome); strcpy(daInserire.Nome, nome); printf (" COGNOME > "); scanf ("%s", cognome); strcpy(daInserire.Cognome, cognome); printf (" TELEFONO > "); scanf ("%s", telefono); strcpy(daInserire.Tel, telefono); printf (" SITOWEB > "); scanf ("%s", sitoweb); strcpy(daInserire.Indirizzopaginaweb, sitoweb); printf (" EMAIL > "); scanf ("%s", email); strcpy(daInserire.Indirizzoemail, email); if(p != NULL){ punt->inf = daInserire; punt->pun = p; } else { p->inf = daInserire; p->pun = NULL; punt = p; } return(punt); } struct elemento *rimuoviContatto(struct elemento *p){ struct elemento *aus; struct elemento *twin = p; int subscelta; int i=1; int n=1; printf (" # RIMUOVI CONTATTO #\n"); while (p != NULL){ printf ("%i) \t %s \t %s\n", i, p->inf.Nome, p->inf.Cognome); p = p->pun; i++; } p = twin; printf("\n\n Inserisci il numero del contatto che vuoi rimuovere: "); scanf("%i", &subscelta); if (subscelta < i){ if(p == NULL) return 0; if(p->pun != NULL){ aus=p; n++; while(n != i){ if(subscelta == n){ aus->pun=aus->pun->pun; } else { aus=aus->pun; } n++; }} if(subscelta == 1){ p=p->pun; }} twin = p; return twin; } bool cerca(struct elemento* p,char *c) { struct elemento *punt=p; bool trovato=false; while((punt!=NULL) && (!trovato)) { if(strcmp(c,punt->inf.Cognome)==0) trovato=true; else punt=punt->pun; } return(trovato); } void *leggiValore(struct elemento* p,char *c){ struct elemento *punt=p; bool trovato=false; while((punt!=NULL) && (!trovato)) { if(strcmp(c,punt->inf.Cognome)==0) trovato=true; else punt=punt->pun; } printf("il valore relativo al contenuto inserito e':\n"); printf (" NOME > %s\n", punt->inf.Nome); printf (" COGNOME > %s\n", punt->inf.Cognome); printf (" TELEFONO > %s\n", punt->inf.Tel); printf (" SITOWEB > %s\n", punt->inf.Indirizzopaginaweb); printf (" EMAIL > %s\n", punt->inf.Indirizzoemail); system("PAUSE"); } void leggi(struct elemento* p,char *c){ if (cerca(p,c)==true) leggiValore(p,c); else{ printf("\n\nERRORE: il valore collegato al contenuto inserito NON ESISTE\n"); system("PAUSE"); }} void Cancella(struct elemento* p){ struct elemento *aux; while (NULL != p){ aux = p; p = p->pun; free(aux); }} int main(){ int scelta; struct elemento *lista = NULL; char c[50]; do{ printf (" 1) VISUALIZZA CONTATTO\n\n"); printf (" 2) AGGIUNGI CONTATTO\n\n"); printf (" 3) RIMUOVI CONTATTO\n\n"); printf (" 4) CERCA CONTATTO\n\n"); printf (" 5) ELIMINA TUTTA LA RUBRICA\n\n"); printf (" 6) ESCI\n\n\n\n"); printf (" la tua scelta > "); scanf("%d",&scelta); system("CLS"); switch(scelta){ case 1:{ visualizzaContatto(lista); break; } case 2:{ lista = aggiungiContatto(lista); break; } case 3:{ lista = rimuoviContatto(lista); break; } case 4:{ printf("Inserisci il cognome che vuoi leggere: \n"); scanf("%s", c); leggi(lista,c); break; } case 5:{ Cancella(lista); lista=NULL; break; } system("PAUSE"); system("CLS"); }}while(scelta!=6); return 0; }
compilate il programma e se potete dammi qualche consiglio ve ne sarei grato
grazie in anticipo

Rispondi quotando
