Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Exception in code C

Exception in code C

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresdebugginghelp
7 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 11658048
    wrote on last edited by
    #1

    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
    #include

    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

    L D P 3 Replies Last reply
    0
    • U User 11658048

      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
      #include

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You will need to use your debugger to find where the exception occurs, and update the question with that information.

      U 1 Reply Last reply
      0
      • L Lost User

        You will need to use your debugger to find where the exception occurs, and update the question with that information.

        U Offline
        U Offline
        User 11658048
        wrote on last edited by
        #3

        in line 54 i have (Liste InsertionOperation(Liste L , Operation op)) Program received signal SIGSEGV

        L 1 Reply Last reply
        0
        • U User 11658048

          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
          #include

          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

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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

          P 1 Reply Last reply
          0
          • U User 11658048

            in line 54 i have (Liste InsertionOperation(Liste L , Operation op)) Program received signal SIGSEGV

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Where exactly is line 54, and what are the values of the variables that are being referenced?

            1 Reply Last reply
            0
            • U User 11658048

              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
              #include

              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

              P Offline
              P Offline
              Philippe Mori
              wrote on last edited by
              #6

              element = 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

              1 Reply Last reply
              0
              • D David Crow

                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

                P Offline
                P Offline
                Philippe Mori
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups