Bonjour,
J’ai une segmentation fault lors de l’exécution de mon programme. Je ne comprends pas d’où provient l’erreur.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define SEUIL 1.001
/* Fonction qui permet d'enlever les lettre non désirées dans le mot */
void deblanck( char * str, int size)
{
int i=0;
for(;i<size && str[i]!=' ';i++);
str[i]='\0';
}
struct
{
int Day;
int Mounth;
int Year;
}typedef DATE_FILE;
/* Cette fonction permet de recuperer les entêtes du fichier,
tel la date de création, la version de NASTRAN */
void getHeader( FILE * FILE_OP2 )
{
long int Word;
DATE_FILE D;
char Name[56];
char Version[56];
char Trailer[56];
fseek(FILE_OP2, sizeof(long int)*4, SEEK_SET);
fread(&D.Day, sizeof(long int), 1, FILE_OP2);
fread(&D.Mounth, sizeof(long int), 1, FILE_OP2);
fread(&D.Year, sizeof(long int), 1, FILE_OP2);
fseek(FILE_OP2, sizeof(long int)*5, SEEK_CUR);
fread(Name, sizeof(long int), 7, FILE_OP2);
deblanck(Name, 28);
fseek(FILE_OP2, sizeof(long int)*12, SEEK_CUR);
fread(Version, sizeof(long int), 3, FILE_OP2);
deblanck(Version, 12);
/* Block contenant aucune information interressante */
fread(Trailer, sizeof(long int), 11, FILE_OP2);
}
/* ************************ STRUCTURE OUG IDENT *****************************
************************************************************************** */
struct
{
long int ACODE;
long int TCODE;
long int MODE;
float EIGN;
float EIGI;
long int NUMWDE;
}typedef OUG_IDENT;
int getIdent( FILE *FILE_OP2 , int END, OUG_IDENT *pIDENT, int *i_IDENT, int *Mode)
{
long int NDW=0;
fread(&pIDENT[*i_IDENT].ACODE, sizeof(long int), 1, FILE_OP2);
fread(&pIDENT[*i_IDENT].TCODE, sizeof(long int), 1, FILE_OP2);
fseek(FILE_OP2, sizeof(long int)*(2), SEEK_CUR);
fread(&pIDENT[*i_IDENT].MODE, sizeof(long int), 1, FILE_OP2);
fread(&pIDENT[*i_IDENT].EIGN, sizeof(long int), 1, FILE_OP2);
fread(&pIDENT[*i_IDENT].EIGI, sizeof(long int), 1, FILE_OP2);
fseek(FILE_OP2, sizeof(long int)*(2), SEEK_CUR);
fread(&pIDENT[*i_IDENT].NUMWDE, sizeof(long int), 1, FILE_OP2);
NDW=(long int)pIDENT[*i_IDENT].NUMWDE;
*Mode=pIDENT[*i_IDENT].MODE;
(*i_IDENT)=(*i_IDENT)+1;
pIDENT=realloc(pIDENT,((*i_IDENT)+1)*sizeof(OUG_IDENT) );
fseek(FILE_OP2, sizeof(unsigned long int)*(END-10), SEEK_CUR);
fseek(FILE_OP2, sizeof(long int)*(13), SEEK_CUR);
return NDW;
}
struct
{
long int MODE;
long int EKEY;
long int TYPE;
float DT1R;
float DT2R;
float DT3R;
float DR1R;
float DR2R;
float DR3R;
float DT1I;
float DT2I;
float DT3I;
float DR1I;
float DR2I;
float DR3I;
}typedef OUG_DATA;
/* Fonction qui récupere les données des modes, selon le nombre de la case de la structure,
on saura si cela est du calcul de reel ou de imaginaire. Pas de vérification avec le TCODE */
void getData( FILE *FILE_OP2 , int END, int NCase, OUG_DATA *pDATA, int *i_DATA, int Mode)
{
long int Tmp;
long int Count=0;
while( Count < (END-4) )
{
pDATA[*i_DATA].MODE=Mode;
fread(&Tmp, sizeof(long int), 1, FILE_OP2);
pDATA[*i_DATA].EKEY=Tmp/10;
fread(&pDATA[*i_DATA].TYPE, sizeof(long int), 1, FILE_OP2);
fread(&pDATA[*i_DATA].DT1R, sizeof(long int), 1, FILE_OP2);
fread(&pDATA[*i_DATA].DT2R, sizeof(long int), 1, FILE_OP2);
fread(&pDATA[*i_DATA].DT3R, sizeof(long int), 1, FILE_OP2);
fread(&pDATA[*i_DATA].DR1R, sizeof(long int), 1, FILE_OP2);
fread(&pDATA[*i_DATA].DR2R, sizeof(long int), 1, FILE_OP2);
fread(&pDATA[*i_DATA].DR3R, sizeof(long int), 1, FILE_OP2);
if( NCase==14 )
{
fread(&pDATA[*i_DATA].DT1I, sizeof(long int), 1, FILE_OP2);
fread(&pDATA[*i_DATA].DT2I, sizeof(long int), 1, FILE_OP2);
fread(&pDATA[*i_DATA].DT3I, sizeof(long int), 1, FILE_OP2);
fread(&pDATA[*i_DATA].DR1I, sizeof(long int), 1, FILE_OP2);
fread(&pDATA[*i_DATA].DR2I, sizeof(long int), 1, FILE_OP2);
fread(&pDATA[*i_DATA].DR3I, sizeof(long int), 1, FILE_OP2);
}
else
{
pDATA[*i_DATA].DT1I=0;
pDATA[*i_DATA].DT2I=0;
pDATA[*i_DATA].DT3I=0;
pDATA[*i_DATA].DR1I=0;
pDATA[*i_DATA].DR2I=0;
pDATA[*i_DATA].DR3I=0;
}
(*i_DATA)=(*i_DATA)+1;
pDATA=realloc(pDATA,((*i_DATA)+1)*sizeof(OUG_DATA) );
Count=Count+NCase;
}
/* Structure de fin de table */
fseek(FILE_OP2, sizeof(long int)*(13), SEEK_CUR);
}
/* ********************************** OUG ***********************************
************************************************************************** */
void getOUG( FILE *FILE_OP2, OUG_IDENT * pIDENT, int *i_IDENT, OUG_DATA *pDATA, int *i_DATA )
{
char Version[24];
char Name[16];
DATE_FILE D;
long int END=0;
long int NbData=0;
int Mode=0;
fseek(FILE_OP2, sizeof(long int)*(5), SEEK_CUR);
fread(Version, sizeof(long int), 3, FILE_OP2);
deblanck(Version, 12);
fseek(FILE_OP2, sizeof(long int)*(8), SEEK_CUR);
/* Structure inconnue */
fseek(FILE_OP2, sizeof(long int)*(8), SEEK_CUR);
/* On supprime la structure de 13 caracteres entre chaque datablock */
fseek(FILE_OP2, sizeof(long int)*(13), SEEK_CUR);
fread( Name, sizeof(long int), 2,FILE_OP2);
deblanck(Name, 8);
if( strcmp( Name, "OUG1" ) == 0 )
{
fread(&D.Day, sizeof(long int), 1, FILE_OP2);
fread(&D.Mounth, sizeof(long int), 1, FILE_OP2);
fread(&D.Year, sizeof(long int), 1, FILE_OP2);
/* On supprime les deux one,one, qui se situe apres la date */
fseek(FILE_OP2, sizeof(long int)*(2), SEEK_CUR);
/* On supprime la structure de 13 caracteres entre chaque datablock */
fseek(FILE_OP2, sizeof(long int)*(13), SEEK_CUR);
fread(&END, sizeof(long int), 1, FILE_OP2);
while ( END!=(long int)4 )
{
/* Recuperation de L'iDENT */
NbData=getIdent( FILE_OP2, (END/4), pIDENT , i_IDENT , &Mode);
fread(&END, sizeof(long int), 1, FILE_OP2);
/* Recuperation des DATA*/
getData( FILE_OP2, (END/4), NbData, pDATA, i_DATA, Mode );
fread(&END, sizeof(long int), 1, FILE_OP2);
}
}
}
int main(int argc, char *argv[])
{
FILE * FILE_OP2;
char Word[8];
int i;
long int nbGrid=0;
/* Vecteur du Rotor */
int *vaRotor;
int *vbRotor;
OUG_DATA *pDATA=(OUG_DATA * )malloc( sizeof(OUG_DATA)*1 );
OUG_IDENT *pIDENT=(OUG_IDENT * )malloc( sizeof(OUG_IDENT)*1 );
int i_iDENT=0;
int i_DATA=0;
if( (FILE_OP2 = fopen( "leapx_v02a_vc_hp.op2" , "rb" )) == 0)
{
fprintf( stderr, " FILE NOT FOUND \n");
system("PAUSE");
exit(EXIT_FAILURE);
}
getHeader(FILE_OP2);
while( !feof(FILE_OP2) )
{
fread(Word, sizeof(long int), 2, FILE_OP2);
deblanck( Word, 8 );
if( (strcmp( Word, "OUGV1")==0) || (strcmp( Word, "OUG1")==0) || (strcmp( Word, "OUG")==0) )
getOUG( FILE_OP2, pIDENT, &i_iDENT, pDATA, &i_DATA );
}
system("PAUSE");
return EXIT_SUCCESS;
}