debug error !

This is a discussion on debug error ! within the C Programming forums, part of the General Programming Boards category; my code is correct but i have debug error ! please help to resolve this problem ... Code: #include <stdio.h> ...

  1. #1
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159

    Question debug error !

    my code is correct but i have debug error !
    please help to resolve this problem ...


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define ns printf("\n\n");
    #define tg printf("\t\t\t");
    
    
    int charint(char c)
    {
    	int ret=1;
    switch(c)
    {
    case'0':ret=0;break;
    case'1':ret=1;break;
    case'2':ret=2;break;
    case'3':ret=3;break;
    case'4':ret=4;break;
    case'5':ret=5;break;
    case'6':ret=6;break;
    case'7':ret=7;break;
    case'8':ret=8;break;
    case'9':ret=9;break;
    default:ret=-1;
    }
    return(ret);
    }
    
    /******* declaration d'un type de structure d'un seule boisson */
    typedef struct nomb
    {
    int quantite;     // q
    int datefin[3];   // f
    int prix;         // x
    int prix_achat;   // a
    char nom[20];     // *
    }nomb;
    /******* fin declaration un boisson ************************************/
    
    void afficher_boisson(int p,nomb *boif)
    {
    	system("cls");
    	for(int i=0;i<80;i++){printf("_");}
    tg
    printf("\01 nom           : %s",(boif+p)->nom);ns
    tg 
    printf("\01 prix          : %i",(boif+p)->prix);ns
    tg 
    printf("\01 prix achat    : %i",(boif+p)->prix_achat);ns	   
    tg
    printf("\01 Quantite      : %i",(boif+p)->quantite);ns
    tg
    printf("\01 Date Fin      : %i/%i/%i\n",(boif+p)->datefin[0],(boif+p)->datefin[1],(boif+p)->datefin[2]);  
    	for(i=0;i<80;i++){printf("_");}
    }
    
    /***************************************** Saisie prix ***********************************/
    void saisieprix(int pos,nomb *boim)
    {
    printf("\01 Donnez nouveaux prix :\n");
    fflush(stdin);
    scanf("%i",&((boim+pos)->prix));
    }
    /*******************************************************************************************/
    /************************************* Saisie prix achat ************************************/
    void saisieprixach(int pos,nomb *boim)
    {
    printf("\01 Donnez nouveau prix d'achat :\n");
    fflush(stdin);
    scanf("%i",&((boim+pos)->prix_achat));
    }
    /*******************************************************************************************/
    /*********************************   Saisie Quantite  **************************************/
    void saisiequantite(int pos,nomb *boim)
    {
    printf("\01 donnez nouvelle Quantite :");
    fflush(stdin);
    scanf("%i",&((boim+pos)->quantite));
    }
    /*******************************************************************************************/
    /***********************************  Saisie Nom ************************************/
    void saisienom(int pos,nomb *boim)
    {
    printf("\01 Donnez nouveau Nom :");
    fflush(stdin);
    gets((boim+pos)->nom);
    
    }
    /*******************************************************************************************/
    void saisiedate(int pos,nomb *boim)
    {
    /*************** prototypes ****************/
    	int charint(char);
    /*******************************************/
    
    int t=0,p=0;
    char ch[50];
    printf("\01 Donnez nouvelle date (jj\\mm\\aa) :");
    fflush(stdin);
    gets(ch);
    
    for(int i=0;;i++)
    {
    if(charint(ch[i])>=0){t=(t*10)+charint(ch[i]);}
    if(charint(ch[i])<0){(boim+pos)->datefin[p]=t;t=0;p++;}
    if(ch[i]==NULL)break;
    }
    
    
    }
    /*******************************************************************************************/
    
    
    
    void ajoutstock(nomb *boij,int *nbst)
    
    {
    	
    
    boij=(nomb*)realloc(boij,sizeof(nomb));
    *nbst++;
            saisieprix(*nbst,boij);
            saisieprixach(*nbst,boij);
            saisiequantite(*nbst,boij);
    	    saisienom(*nbst,boij);
    		saisiedate(*nbst,boij);
    
    
    }
    
    void main()
    {
    nomb *bois;
    	int nb_boissons=0;
        ajoutstock(bois,&nb_boissons);
        afficher_boisson(nb_boissons,bois);
    
    
    
    }

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Post the error.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    void main, fflush(stdin), horrible indenting... where to begin?

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Indeed, main returns an int, stdin shouldn't be flushed, and yes, indent your code better. But don't forget to tell us the error. We're helping you as it is, you can at least do us a favor and not require us to compile your code.

  5. #5
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    i'm in cybercafe so i doin't have compiler

    Code:
     someone compile this ...

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Well there are many errors. Void main is among them. There are also many errors that are caused depending on how you're compiling this (under what standard). Other errors are reported in some compilers but not others.

  7. #7
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    can you explain please...
    (i compile this whith visual c++)
    but the principal error should be in
    Code:
    void ajoutstock(nomb *boij,int *nbst)
    
    {
    	
    
    boij=(nomb*)realloc(boij,sizeof(nomb));
    *nbst++;

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well for starters, if you actually plan on changing what the pointer points to when you pass it to a function, you need to be passing a pointer to a pointer instead. Otherwise when the function ends, your realloc is in effect thrown out the window.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    void foo( char *bar )
    {
        bar = malloc( 10 );
    }
    
    int main( void )
    {
        char array[] = "See?";
        char *ptr = array;
        foo( ptr );
        printf("%s\n", ptr );
        return 0;
    }

    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    --------> correct code ?
    explain me please...

    Code:
    void main()
    {
    nomb *bois;
    	int nb_boissons=0;
    bois=(nomb*)malloc(sizeof(nomb));
    ajoutstock(bois,&nb_boissons);
    afficher_boisson(nb_boissons,bois);
    
    }

  10. #10
    Helper
    Join Date
    Jun 2004
    Posts
    255
    Quote Originally Posted by enjoy
    my code is correct but i have debug error !
    please help to resolve this problem ...
    Your code is not correct at all. Here is a quick fix (C90). It is still full of undefined behaviours.

    The macros are ugly...
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define ns printf("\n\n");
    #define tg printf("\t\t\t");
    
    int charint (char c)
    {
       int ret = 1;
       switch (c)
       {
       case '0':
          ret = 0;
          break;
       case '1':
          ret = 1;
          break;
       case '2':
          ret = 2;
          break;
       case '3':
          ret = 3;
          break;
       case '4':
          ret = 4;
          break;
       case '5':
          ret = 5;
          break;
       case '6':
          ret = 6;
          break;
       case '7':
          ret = 7;
          break;
       case '8':
          ret = 8;
          break;
       case '9':
          ret = 9;
          break;
       default:
          ret = -1;
       }
       return (ret);
    }
    
    /******* declaration d'un type de structure d'un seule boisson */
    typedef struct nomb
    {
       int quantite;                /* q */
    
       int datefin[3];              /* f */
    
       int prix;                    /* x */
    
       int prix_achat;              /* a */
    
       char nom[20];                /* * */
    
    }
    nomb;
    /******* fin declaration un boisson ************************************/
    
    void afficher_boisson (int p, nomb * boif)
    {
       int i;
       system ("cls");
       for (i = 0; i < 80; i++)
       {
          printf ("_");
       }
       tg
          printf ("\01 nom           : %s", (boif + p)->nom);
       ns
          tg
          printf ("\01 prix          : %i", (boif + p)->prix);
       ns
          tg
          printf ("\01 prix achat    : %i", (boif + p)->prix_achat);
       ns
          tg
          printf ("\01 Quantite      : %i", (boif + p)->quantite);
       ns
          tg
          printf ("\01 Date Fin      : %i/%i/%i\n", (boif + p)->datefin[0], (boif + p)->datefin[1], (boif + p)->datefin[2]);
       for (i = 0; i < 80; i++)
       {
          printf ("_");
       }
    }
    
    /***************************************** Saisie prix ***********************************/
    void saisieprix (int pos, nomb * boim)
    {
       printf ("\01 Donnez nouveaux prix :\n");
       fflush (stdin);
       scanf ("%i", &((boim + pos)->prix));
    }
    /**************************************************  *****************************************/
    /************************************* Saisie prix achat ************************************/
    void saisieprixach (int pos, nomb * boim)
    {
       printf ("\01 Donnez nouveau prix d'achat :\n");
       fflush (stdin);
       scanf ("%i", &((boim + pos)->prix_achat));
    }
    /**************************************************  *****************************************/
    /*********************************   Saisie Quantite  **************************************/
    void saisiequantite (int pos, nomb * boim)
    {
       printf ("\01 donnez nouvelle Quantite :");
       fflush (stdin);
       scanf ("%i", &((boim + pos)->quantite));
    }
    /**************************************************  *****************************************/
    /***********************************  Saisie Nom ************************************/
    void saisienom (int pos, nomb * boim)
    {
       printf ("\01 Donnez nouveau Nom :");
       fflush (stdin);
       gets ((boim + pos)->nom);
    
    }
    /**************************************************  *****************************************/
    void saisiedate (int pos, nomb * boim)
    {
    /*************** prototypes ****************/
       int charint (char);
    /*******************************************/
    
       int t = 0, p = 0;
       int i;
       char ch[50];
       printf ("\01 Donnez nouvelle date (jj\\mm\\aa) :");
       fflush (stdin);
       gets (ch);
    
       for (i = 0;; i++)
       {
          if (charint (ch[i]) >= 0)
          {
             t = (t * 10) + charint (ch[i]);
          }
          if (charint (ch[i]) < 0)
          {
             (boim + pos)->datefin[p] = t;
             t = 0;
             p++;
          }
          if (ch[i] == NULL)
             break;
       }
    
    }
    /**************************************************  *****************************************/
    
    void ajoutstock (nomb * boij, int *nbst)
    
    {
    
       boij = (nomb *) realloc (boij, sizeof (nomb));
       *nbst++;
       saisieprix (*nbst, boij);
       saisieprixach (*nbst, boij);
       saisiequantite (*nbst, boij);
       saisienom (*nbst, boij);
       saisiedate (*nbst, boij);
    
    }
    
    int main (void)
    {
       nomb *bois;
       int nb_boissons = 0;
       ajoutstock (bois, &nb_boissons);
       afficher_boisson (nb_boissons, bois);
       return 0;
    }
    Note also that you can find French speaking C-experts at 'http://www.developpez.com'
    Emmanuel Delahaye

    "C is a sharp tool"

  11. #11
    Helper
    Join Date
    Jun 2004
    Posts
    255
    Quote Originally Posted by enjoy
    i'm in cybercafe so i doin't have compiler
    Code:
     someone compile this ...
    Try an online C-compiler at :

    http://www.comeaucomputing.com/tryitout/
    Emmanuel Delahaye

    "C is a sharp tool"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  3. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  4. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  5. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21