|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Dec 2001
Città: Partinico(PA)-Torino
Messaggi: 2885
|
problemino di C...
Dunque ho implementato in c la seguente funzione:
int cancella(NODO **root, RECORD buffer) { int x, y; NODO *paus, *paus2; if(*root==NULL) return 0; else{ x=(strcmp(buffer.cognome, (*root)->info.cognome)); if(x<0) return( cancella(&((*root)->sx), buffer)); if(x>0) return( cancella(&((*root)->dx), buffer)); if(x==0) { y=(strcmp(buffer.nome, (*root)->info.nome)); if(y<0) return( cancella(&((*root)->sx), buffer)); if(y>0) return( cancella(&((*root)->dx), buffer)); else /* è stato trovato il punto da eliminare*/ { /*analisi dei vari casi*/ /*se *root non ha figli*/ if((((*root)->dx)==NULL)&&(((*root)->sx)==NULL)) free(*root); /*se *root ha il solo figlio sinistro*/ if((*root)->dx==NULL) { paus=*root; *root=(*root)->sx; free(paus); } /*se *root ha il solo figlio destro*/ if((*root)->sx==NULL) { paus=*root; *root=(*root)->dx; free(paus); } /*se invece ha tutti e due i figli*/ else{ if((((*root)->sx)!=NULL)&&(((*root)->dx)!=NULL)) { paus=*root; paus2=(*root)->sx; *root=(*root)->dx; free(paus); if((*root)->sx==NULL) { (*root)->sx=paus2; free(paus2); } else { while((*root)->sx!=NULL) { ((*root)->sx)=((*root)->sx);/*scorre in avanti il puntatore*/ } (*root)->sx=paus2; free(paus2); } } } } } } return 1; } Essa opera in un programmino che simula una rubrica telefonica e serve a cancellarne una voce. Al momento della compilazione del programma è tutto ok...ma nell'esecuzione di fatto c'è qualcosa che non va infatti mi dice "segmentantion fault" ed esce dal programma... Vi sarei molto grato se mi aiutaste a risolvere il problema.Grazie.
__________________
Main: Barton 2500@3200+ Asus A7N8X-dlx 2*512 DDRPowercolor 9800Pro Maxtor 80GB sATA + Seagate 160GB pATA LCD Acer AL1721 Epson C62 Antec T.P. 430w Tin.it ADSL Muletto: Pentium4 1800 Notebook: Idea Progress P4 Auto e moto d'epoca
|
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Re: problemino di C...
int cancella(NODO **root, RECORD buffer)
{ int x, y; NODO *paus, *paus2; if(*root==NULL) return 0; else{ x=(strcmp(buffer.cognome, (*root)->info.cognome)); if(x<0) return( cancella(&((*root)->sx), buffer)); if(x>0) return( cancella(&((*root)->dx), buffer)); if(x==0) { y=(strcmp(buffer.nome, (*root)->info.nome)); if(y<0) return( cancella(&((*root)->sx), buffer)); if(y>0) return( cancella(&((*root)->dx), buffer)); else /* è stato trovato il punto da eliminare*/ { /*analisi dei vari casi*/ /*se *root non ha figli*/ if((((*root)->dx)==NULL)&&(((*root)->sx)==NULL)) { free(*root); *root = NULL; return 1; } /*se *root ha il solo figlio sinistro*/ if((*root)->dx==NULL) { paus=*root; *root=(*root)->sx; free(paus); return 1; } /*se *root ha il solo figlio destro*/ if((*root)->sx==NULL) { paus=*root; *root=(*root)->dx; free(paus); return 1; } /*se invece ha tutti e due i figli*/ else{ if((((*root)->sx)!=NULL)&&(((*root)->dx)!=NULL)) { paus=*root; paus2=(*root)->sx; *root=(*root)->dx; free(paus); if((*root)->sx==NULL) { (*root)->sx=paus2; free(paus2); // ??????? } else { while((*root)->sx!=NULL) { ((*root)->sx)=((*root)->sx);/*scorre in avanti il puntatore*/ } (*root)->sx=paus2; free(paus2); // ?????????? } } } } } } return 1; }
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Dec 2001
Città: Partinico(PA)-Torino
Messaggi: 2885
|
perkè hai messo quei punti interrogativi???
__________________
Main: Barton 2500@3200+ Asus A7N8X-dlx 2*512 DDRPowercolor 9800Pro Maxtor 80GB sATA + Seagate 160GB pATA LCD Acer AL1721 Epson C62 Antec T.P. 430w Tin.it ADSL Muletto: Pentium4 1800 Notebook: Idea Progress P4 Auto e moto d'epoca
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Rimuovi quelle righe orrende
Ti metto la pulce nell'orecchio: Questo (*root)->sx=paus2; free(paus2) E' equivalente a questo (*root)->sx=paus2; free((*root)->sx)
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Dec 2001
Città: Partinico(PA)-Torino
Messaggi: 2885
|
Madonna ke caz*ata che avevo scritto!
Forse ultimamente ho fatto troppo abuso di C... Thank you, very much!
__________________
Main: Barton 2500@3200+ Asus A7N8X-dlx 2*512 DDRPowercolor 9800Pro Maxtor 80GB sATA + Seagate 160GB pATA LCD Acer AL1721 Epson C62 Antec T.P. 430w Tin.it ADSL Muletto: Pentium4 1800 Notebook: Idea Progress P4 Auto e moto d'epoca
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 19:36.










Main: Barton 2500@3200+ Asus A7N8X-dlx 2*512 DDRPowercolor 9800Pro Maxtor 80GB sATA + Seagate 160GB pATA LCD Acer AL1721 Epson C62 Antec T.P. 430w Tin.it ADSL Muletto: Pentium4 1800 Notebook: Idea Progress P4 







