Click here to Skip to main content
14,298,358 members

C / C++ / MFC

 
AnswerRe: An analog switch, but more efficient Pin
jeron115-May-15 5:06
memberjeron115-May-15 5:06 
QuestionCalculating average in a high priority thread Pin
Member 935023714-May-15 23:18
memberMember 935023714-May-15 23:18 
GeneralRe: Calculating average in a high priority thread Pin
Jochen Arndt14-May-15 23:27
mveJochen Arndt14-May-15 23:27 
GeneralRe: Calculating average in a high priority thread Pin
Member 935023714-May-15 23:36
memberMember 935023714-May-15 23:36 
GeneralRe: Calculating average in a high priority thread Pin
Jochen Arndt14-May-15 23:42
mveJochen Arndt14-May-15 23:42 
GeneralRe: Calculating average in a high priority thread Pin
Member 935023715-May-15 0:19
memberMember 935023715-May-15 0:19 
GeneralRe: Calculating average in a high priority thread Pin
Jochen Arndt15-May-15 0:53
mveJochen Arndt15-May-15 0:53 
QuestionException in code C Pin
Member 1169244814-May-15 21:33
memberMember 1169244814-May-15 21:33 
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.
SuggestionRe: Exception in code C Pin
Richard MacCutchan14-May-15 22:35
protectorRichard MacCutchan14-May-15 22:35 
GeneralRe: Exception in code C Pin
Member 1169244814-May-15 22:59
memberMember 1169244814-May-15 22:59 
GeneralRe: Exception in code C Pin
Richard MacCutchan15-May-15 2:53
protectorRichard MacCutchan15-May-15 2:53 
SuggestionRe: Exception in code C Pin
David Crow15-May-15 2:13
memberDavid Crow15-May-15 2:13 
GeneralRe: Exception in code C Pin
Philippe Mori16-May-15 2:45
memberPhilippe Mori16-May-15 2:45 
AnswerRe: Exception in code C Pin
Philippe Mori16-May-15 2:41
memberPhilippe Mori16-May-15 2:41 
QuestionCopy Text from dialog box Pin
Thakur JAI SINGH13-May-15 23:31
memberThakur JAI SINGH13-May-15 23:31 
AnswerRe: Copy Text from dialog box Pin
Richard MacCutchan14-May-15 1:22
protectorRichard MacCutchan14-May-15 1:22 
QuestionRe: Copy Text from dialog box Pin
David Crow14-May-15 4:04
memberDavid Crow14-May-15 4:04 
AnswerRe: Copy Text from dialog box Pin
Thakur JAI SINGH18-May-15 0:48
memberThakur JAI SINGH18-May-15 0:48 
QuestionRe: Copy Text from dialog box Pin
David Crow18-May-15 2:21
memberDavid Crow18-May-15 2:21 
QuestionMFC release and Debug build Pin
bhushan050812-May-15 0:42
memberbhushan050812-May-15 0:42 
GeneralRe: MFC release and Debug build Pin
Richard MacCutchan12-May-15 4:57
protectorRichard MacCutchan12-May-15 4:57 
AnswerRe: MFC release and Debug build Pin
Maximilien12-May-15 7:52
memberMaximilien12-May-15 7:52 
GeneralRe: MFC release and Debug build Pin
Albert Holguin12-May-15 10:26
professionalAlbert Holguin12-May-15 10:26 
GeneralRe: MFC release and Debug build Pin
Maximilien13-May-15 3:13
memberMaximilien13-May-15 3:13 
AnswerRe: MFC release and Debug build Pin
Albert Holguin12-May-15 10:30
professionalAlbert Holguin12-May-15 10:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.