Exception in code C
-
Hello, This is my code. When i compile and execute it i have the following error:
1 [main] test 5952 exception::handle: Exception: STATUS_ACCESS_VIOLATION
722 [main] test 5952 open_stackdumpfile: Dumping stack trace to test.exe.sta
ckdump#include
#include
#includetypedef struct Date{
int J ;
int M ;
int A ;
} Date;typedef struct Operation{
char Obj[30];
float Mnt ;
Date Date_Tr ;
int Type_Tr ;
int Etat ;
} Operation;typedef struct Cellule{
Operation Info ;
struct Cellule *succ ;
} Cellule ;typedef Cellule * Liste ;
int EgaliteDates(Date d1 , Date d2)
{
if ((d1.J==d2.J) && (d1.M==d2.M) && (d1.A==d2.A))
return 0;
else
{
if ((d1.A>d2.A) || ((d1.A==d2.A) && (d1.M>d2.M)) || (((d1.A==d2.A) && (d1.M==d2.A) && (d1.J==d2.J))))
return 1;
else
return 2;
}
}
Liste InsertionOperation(Liste L , Operation op)
{Liste temp; Liste pred; Liste element; element = malloc(sizeof(Liste)); element->Info = op; element->succ = NULL; if(L == NULL) { L=element; } else { if (EgaliteDates(L->Info.Date\_Tr,op.Date\_Tr)==2) { element->succ= L; L=element; } else { temp=L; pred=L; while((temp->succ != NULL) && (EgaliteDates(temp->Info.Date\_Tr,op.Date\_Tr)<2)) { pred=temp; temp = temp->succ; } element->succ=temp->succ; pred->succ = element; } } return L;
}
void afficherListe(Liste L)
{
Cellule *tmp = L;
int i=0;
while(tmp != NULL)
{
i++;
printf("Objet %d : %s, montant: %f, date : %d %d %d, type: %s\n", i,tmp->Info.Obj,tmp->Info.Mnt,tmp->Info.Date_Tr.J,tmp->Info.Date_Tr.M,tmp->Info.Date_Tr.M,tmp->Info.Type_Tr,tmp->Info.Etat);
tmp = tmp->succ;
}
}void RechercheDate(Liste L, Date minDate , Date maxDate )
{
Cellule *tmp = L;
printf("liste des objets entre %d/%d/%d et %d/%d/%d: \n",minDate.J,minDate.M,minDate.A,maxDate.J,maxDate.M,maxDate.A);
while(tmp != NULL)
{
if ((EgaliteDates(tmp->Info.Date_Tr , maxDate)<2) && (EgaliteDates(minDate,tmp->Info.Date_Tr)<2))
printf("Objet : %s, montant: %f, date : %d %d %d, type: %s\n",tmp->Info.Obj,tmp->Info.Mnt,tmp->Info.Date_Tr.J,tmp->Info.Date_Tr.M,tmp->Info.Date_Tr.M,tmp->Info.Type_Tr,tmp->Info.Etat);
tmp -
Hello, This is my code. When i compile and execute it i have the following error:
1 [main] test 5952 exception::handle: Exception: STATUS_ACCESS_VIOLATION
722 [main] test 5952 open_stackdumpfile: Dumping stack trace to test.exe.sta
ckdump#include
#include
#includetypedef struct Date{
int J ;
int M ;
int A ;
} Date;typedef struct Operation{
char Obj[30];
float Mnt ;
Date Date_Tr ;
int Type_Tr ;
int Etat ;
} Operation;typedef struct Cellule{
Operation Info ;
struct Cellule *succ ;
} Cellule ;typedef Cellule * Liste ;
int EgaliteDates(Date d1 , Date d2)
{
if ((d1.J==d2.J) && (d1.M==d2.M) && (d1.A==d2.A))
return 0;
else
{
if ((d1.A>d2.A) || ((d1.A==d2.A) && (d1.M>d2.M)) || (((d1.A==d2.A) && (d1.M==d2.A) && (d1.J==d2.J))))
return 1;
else
return 2;
}
}
Liste InsertionOperation(Liste L , Operation op)
{Liste temp; Liste pred; Liste element; element = malloc(sizeof(Liste)); element->Info = op; element->succ = NULL; if(L == NULL) { L=element; } else { if (EgaliteDates(L->Info.Date\_Tr,op.Date\_Tr)==2) { element->succ= L; L=element; } else { temp=L; pred=L; while((temp->succ != NULL) && (EgaliteDates(temp->Info.Date\_Tr,op.Date\_Tr)<2)) { pred=temp; temp = temp->succ; } element->succ=temp->succ; pred->succ = element; } } return L;
}
void afficherListe(Liste L)
{
Cellule *tmp = L;
int i=0;
while(tmp != NULL)
{
i++;
printf("Objet %d : %s, montant: %f, date : %d %d %d, type: %s\n", i,tmp->Info.Obj,tmp->Info.Mnt,tmp->Info.Date_Tr.J,tmp->Info.Date_Tr.M,tmp->Info.Date_Tr.M,tmp->Info.Type_Tr,tmp->Info.Etat);
tmp = tmp->succ;
}
}void RechercheDate(Liste L, Date minDate , Date maxDate )
{
Cellule *tmp = L;
printf("liste des objets entre %d/%d/%d et %d/%d/%d: \n",minDate.J,minDate.M,minDate.A,maxDate.J,maxDate.M,maxDate.A);
while(tmp != NULL)
{
if ((EgaliteDates(tmp->Info.Date_Tr , maxDate)<2) && (EgaliteDates(minDate,tmp->Info.Date_Tr)<2))
printf("Objet : %s, montant: %f, date : %d %d %d, type: %s\n",tmp->Info.Obj,tmp->Info.Mnt,tmp->Info.Date_Tr.J,tmp->Info.Date_Tr.M,tmp->Info.Date_Tr.M,tmp->Info.Type_Tr,tmp->Info.Etat);
tmp -
You will need to use your debugger to find where the exception occurs, and update the question with that information.
in line 54 i have (Liste InsertionOperation(Liste L , Operation op)) Program received signal SIGSEGV
-
Hello, This is my code. When i compile and execute it i have the following error:
1 [main] test 5952 exception::handle: Exception: STATUS_ACCESS_VIOLATION
722 [main] test 5952 open_stackdumpfile: Dumping stack trace to test.exe.sta
ckdump#include
#include
#includetypedef struct Date{
int J ;
int M ;
int A ;
} Date;typedef struct Operation{
char Obj[30];
float Mnt ;
Date Date_Tr ;
int Type_Tr ;
int Etat ;
} Operation;typedef struct Cellule{
Operation Info ;
struct Cellule *succ ;
} Cellule ;typedef Cellule * Liste ;
int EgaliteDates(Date d1 , Date d2)
{
if ((d1.J==d2.J) && (d1.M==d2.M) && (d1.A==d2.A))
return 0;
else
{
if ((d1.A>d2.A) || ((d1.A==d2.A) && (d1.M>d2.M)) || (((d1.A==d2.A) && (d1.M==d2.A) && (d1.J==d2.J))))
return 1;
else
return 2;
}
}
Liste InsertionOperation(Liste L , Operation op)
{Liste temp; Liste pred; Liste element; element = malloc(sizeof(Liste)); element->Info = op; element->succ = NULL; if(L == NULL) { L=element; } else { if (EgaliteDates(L->Info.Date\_Tr,op.Date\_Tr)==2) { element->succ= L; L=element; } else { temp=L; pred=L; while((temp->succ != NULL) && (EgaliteDates(temp->Info.Date\_Tr,op.Date\_Tr)<2)) { pred=temp; temp = temp->succ; } element->succ=temp->succ; pred->succ = element; } } return L;
}
void afficherListe(Liste L)
{
Cellule *tmp = L;
int i=0;
while(tmp != NULL)
{
i++;
printf("Objet %d : %s, montant: %f, date : %d %d %d, type: %s\n", i,tmp->Info.Obj,tmp->Info.Mnt,tmp->Info.Date_Tr.J,tmp->Info.Date_Tr.M,tmp->Info.Date_Tr.M,tmp->Info.Type_Tr,tmp->Info.Etat);
tmp = tmp->succ;
}
}void RechercheDate(Liste L, Date minDate , Date maxDate )
{
Cellule *tmp = L;
printf("liste des objets entre %d/%d/%d et %d/%d/%d: \n",minDate.J,minDate.M,minDate.A,maxDate.J,maxDate.M,maxDate.A);
while(tmp != NULL)
{
if ((EgaliteDates(tmp->Info.Date_Tr , maxDate)<2) && (EgaliteDates(minDate,tmp->Info.Date_Tr)<2))
printf("Objet : %s, montant: %f, date : %d %d %d, type: %s\n",tmp->Info.Obj,tmp->Info.Mnt,tmp->Info.Date_Tr.J,tmp->Info.Date_Tr.M,tmp->Info.Date_Tr.M,tmp->Info.Type_Tr,tmp->Info.Etat);
tmpSingle step through the code using the debugger.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
in line 54 i have (Liste InsertionOperation(Liste L , Operation op)) Program received signal SIGSEGV
-
Hello, This is my code. When i compile and execute it i have the following error:
1 [main] test 5952 exception::handle: Exception: STATUS_ACCESS_VIOLATION
722 [main] test 5952 open_stackdumpfile: Dumping stack trace to test.exe.sta
ckdump#include
#include
#includetypedef struct Date{
int J ;
int M ;
int A ;
} Date;typedef struct Operation{
char Obj[30];
float Mnt ;
Date Date_Tr ;
int Type_Tr ;
int Etat ;
} Operation;typedef struct Cellule{
Operation Info ;
struct Cellule *succ ;
} Cellule ;typedef Cellule * Liste ;
int EgaliteDates(Date d1 , Date d2)
{
if ((d1.J==d2.J) && (d1.M==d2.M) && (d1.A==d2.A))
return 0;
else
{
if ((d1.A>d2.A) || ((d1.A==d2.A) && (d1.M>d2.M)) || (((d1.A==d2.A) && (d1.M==d2.A) && (d1.J==d2.J))))
return 1;
else
return 2;
}
}
Liste InsertionOperation(Liste L , Operation op)
{Liste temp; Liste pred; Liste element; element = malloc(sizeof(Liste)); element->Info = op; element->succ = NULL; if(L == NULL) { L=element; } else { if (EgaliteDates(L->Info.Date\_Tr,op.Date\_Tr)==2) { element->succ= L; L=element; } else { temp=L; pred=L; while((temp->succ != NULL) && (EgaliteDates(temp->Info.Date\_Tr,op.Date\_Tr)<2)) { pred=temp; temp = temp->succ; } element->succ=temp->succ; pred->succ = element; } } return L;
}
void afficherListe(Liste L)
{
Cellule *tmp = L;
int i=0;
while(tmp != NULL)
{
i++;
printf("Objet %d : %s, montant: %f, date : %d %d %d, type: %s\n", i,tmp->Info.Obj,tmp->Info.Mnt,tmp->Info.Date_Tr.J,tmp->Info.Date_Tr.M,tmp->Info.Date_Tr.M,tmp->Info.Type_Tr,tmp->Info.Etat);
tmp = tmp->succ;
}
}void RechercheDate(Liste L, Date minDate , Date maxDate )
{
Cellule *tmp = L;
printf("liste des objets entre %d/%d/%d et %d/%d/%d: \n",minDate.J,minDate.M,minDate.A,maxDate.J,maxDate.M,maxDate.A);
while(tmp != NULL)
{
if ((EgaliteDates(tmp->Info.Date_Tr , maxDate)<2) && (EgaliteDates(minDate,tmp->Info.Date_Tr)<2))
printf("Objet : %s, montant: %f, date : %d %d %d, type: %s\n",tmp->Info.Obj,tmp->Info.Mnt,tmp->Info.Date_Tr.J,tmp->Info.Date_Tr.M,tmp->Info.Date_Tr.M,tmp->Info.Type_Tr,tmp->Info.Etat);
tmpelement = malloc(sizeof(Liste));
should be
element = malloc(sizeof(Cellule));
You are allocating 4 bytes (on 32 bit platform) instead of approximatively 60 bytes. The following line is also incorrect:
en_cours=en_cours->succ;
Since you are Inside a function, the pointer is passed by value and a change inside the function has no effect outside of it. You need to have a pointer to a pointer to be able to update the pointer at the caller location. You don't initialized new list to NULL so first insertion might fails because the pointer is garbage.
Philippe Mori
-
Single step through the code using the debugger.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
And test one function at a time for each case. Put breakpoint in each branch and ensure you test each one or better yet, make unit test for each one.
Philippe Mori