Ho un problema, ma non riesco a capire dove sbaglio...
Ho un file di testo formattato nel modo seguente:
ID: 1
COGNOME: Rossi
NOME: Mario
ID: 2
COGNOME: Verdi
NOME: Giovanni
...
...
...
etc.
ho buttato giù qualche linea di codice per acquisire le informazioni dal file nella mia struttura dati array...ma mi va in segmentation fault e non capisco perchè...
HELPPP!
Codice PHP:
#include "Agenda.h"
void Read( AGENDA **Agenda, int *ID )
{
FILE *fpAGENDA;
char FileName[16],
strbuff[64];
AGENDA *Temp;
int ContID;
Temp=*Agenda; /* Copio l'Agenda attuale in un'Array Temp */
ContID = *ID; /* Copio il numero di Contatti Attuale in ContID */
strcpy(FileName, "Agenda.txt" );
if( ( fpAGENDA = fopen( FileName, "r" ) ) == 0 )
{
system("CLS");
printf("\n\a ERRORE: Impossibile aprire il file %s\n\n", FileName );
system("PAUSE");
system("CLS");
}
else
{
/* Alloco lo spazio necessario in memoria per inserire un nuovo NOMINATIVO */
Temp =(AGENDA*)realloc( *Agenda , (ContID+1) * sizeof( AGENDA ) );
/* Inizializzo i sotto-array NumTel, Indirizzo, Email, AltriRecapiti */
InitStruct( &Temp, ContID );
do
{
Temp =(AGENDA*)realloc( &(*Temp) , (ContID+1) * sizeof( AGENDA ) );
fscanf(fpAGENDA, "%s", strbuff);
if( strcmp(strbuff,"ID:")==0)
fscanf(fpAGENDA, "%d", &Temp[ContID].Identita.ID);
fscanf(fpAGENDA, "%s", strbuff);
if( strcmp(strbuff,"COGNOME:")==0)
fgets(Temp[ContID].Identita.Cognome, 32, fpAGENDA);
fscanf(fpAGENDA, "%s", strbuff);
if( strcmp(strbuff,"NOME:")==0)
fgets(Temp[ContID].Identita.Nome, 32, fpAGENDA);
ContID++;
}
while( !feof( fpAGENDA ) );
}
*Agenda = Temp;
*ID = ContID;
free(Temp);
}