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 <stdio.h>
#include<stdlib.h>
#include<string.h>
typedef 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 = tmp->succ;
}
}
void ReglerOp(Liste en_cours , Liste reglee, char obj_op[])
{
Cellule *tmp = en_cours;
Cellule *pred = en_cours;
while((tmp != NULL) && (strcmp(en_cours->Info.Obj,obj_op) != 0))
{
pred=tmp;
tmp = tmp->succ;
}
if (tmp==en_cours)
en_cours=en_cours->succ;
else
pred->succ=tmp->succ;
tmp->Info.Etat=1;
InsertionOperation(reglee , tmp->Info);
free(tmp);
}
main()
{
Date d1 = {2,10,2012};
Date d2 = {2,12,2012};
Date d3 = {12,10,2012};
Date d4 = {10,12,2011};
Date d5 = {2,10,2012};
Date d6 = {2,10,2012};
printf("Comapraison %d/%d/%d et %d/%d/%d donne %d\n",d1.J,d1.M,d1.A,d2.J,d2.M,d2.A,EgaliteDates(d1 , d2));
printf("Comapraison %d/%d/%d et %d/%d/%d donne %d\n",d3.J,d3.M,d3.A,d4.J,d4.M,d4.A,EgaliteDates(d3 , d4));
printf("Comapraison %d/%d/%d et %d/%d/%d donne %d\n",d5.J,d5.M,d5.A,d6.J,d6.M,d6.A,EgaliteDates(d5 , d6));
Liste L;
Operation op1= {"objet1",23.5,{30,3,2012},1,1};
Operation op2= {"objet2",24.5,{2,2,2012},1,1};
Operation op3= {"objet3",25.5,{12,4,2013},1,1};
Operation op4= {"objet4",26.5,{15,10,2014},1,1};
Operation op5= {"objet5",27.5,{9,8,2014},1,1};
Operation op6= {"objet6",28.5,{10,11,2015},1,1};
L=InsertionOperation(L , op1);
L=InsertionOperation(L , op2);
L=InsertionOperation(L , op3);
L=InsertionOperation(L , op4);
L=InsertionOperation(L , op5);
L=InsertionOperation(L , op6);
printf("\n liste réglée \n");
afficherListe(L);
Date dmin = {1,1,2014};
Date dmax = {30,12,2015};
RechercheDate(L,dmin,dmax);
Liste en_cours;
Operation ec1= {"ec1",20.5,{7,2,2012},2,0};
Operation ec2= {"ec2",33.5,{30,3,2010},2,0};
Operation ec3= {"ec3",43.5,{9,12,2014},2,0};
Operation ec4= {"ec4",53.5,{10,10,2013},2,0};
L=InsertionOperation(en_cours , ec1);
L=InsertionOperation(en_cours, ec2);
L=InsertionOperation(en_cours , ec3);
L=InsertionOperation(en_cours , ec4);
printf("\n liste en cours \n");
afficherListe(en_cours);
ReglerOp(en_cours , L, "ec4");
ReglerOp(en_cours , L, "ec1");
printf("\n liste réglée \n");
afficherListe(L);
printf("\n liste en cours \n");
afficherListe(en_cours);
}
So what is wrong with my code and how can i fix it?
Thanks.
|