Thread: lites (debug error )

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

    Red face listes (---------------------debug error---------------------- )

    hello to all programmers

    syntaxe is ok ...

    but when i enter the number of element list then i enter the first number ---> debug error !!

    here is my code
    Code:
    #include <stdlib.h>
    #include <conio.h>
    #include <stdio.h>
    
    typedef struct cellule
    {
    int info;
    cellule *suivant;
    
    }cellule, *liste;
    
    
    
    /******************************************************************/
    liste nouveau(){return NULL; }
    /******************************************************************/
    liste suivant(liste p){ return(p->suivant); }
    /******************************************************************/
    int debut(liste l){  return l->info ; }
    /******************************************************************/
    
    void afficher(liste tete)
    {
    liste p;
    p=tete;
    printf("\n\n");
    printf("\n-----------------------------------------------------\n");
    while(p!=NULL)
    {
    printf(" %d", p->info );
    p=suivant(p);
    }
    printf("\n-----------------------------------------------------\n");
    
    
    }
    
    liste ajoutfin(liste l, int a )
    {
    
    liste p1,p2;
    
    liste N=(liste)malloc(sizeof(liste));
    
    if (N!=NULL)
    {
    	N->info=a;
    	N->suivant=NULL;
    }
    
    
    liste remplir_tete(liste p)
    {
    
    int n,a;
    
    printf("Entrer le nombre d'elements de la liste: ");scanf("%d",&n);
    
    
    for(int i=0; i<n ; i++)
    {
      printf("Entrer l'element %i: \n",i+1);
      scanf("%i",&a);
     p=ajoutfin(p,a);
    return(p);
    }
    
    
    int main()
    {
    liste l;
    
    l=nouveau();
    printf("saisie liste 1 --> remplir_tete\n");
    l=remplir_tete(l);
    afficher(l);
    return(1);
    }
    ----------------------------------------
    thanks for help ...
    Last edited by enjoy; 01-07-2005 at 03:24 PM. Reason: wrong code

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

    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$
    any one try to help me ....
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > syntaxe is ok ...
    Erm, no it isn't

    > iste ajoutfin(liste l, int a )
    There is no 'iste' and it's braces are unbalanced.

    > t=nouveau();
    t is undeclared.

    And your indentation sucks.

    > liste remplir_tete(liste p)
    Try ending this function with
    return p;

    > liste N=(liste)malloc(sizeof(liste));
    Read the FAQ - there's no reason why you should be casting malloc in C.

    You sure are an impatient little troll aren't you
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    now it's ok my code

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    No, include all your header files, and indent it properly
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    what's the wrong in malloc function
    our professor use malloc and calloc ...

  7. #7
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You shouldn't cast the return value of malloc().
    Code:
    char *ptr = malloc(5);
    ...works just fine.
    If you understand what you're doing, you're not learning anything.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> now it's ok my code

    well, in addition to what's already been said, you're not appending the data to the end of the list. the return statement in remplir_tete() doesn't make much sense either.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    Now that's what I call indentation - learn to do something like it enjoy
    Code:
    #include <stdlib.h>
    /*#include <conio.h> NOT NEEDED */
    #include <stdio.h>
    
    typedef struct cellule {
        int info;
        struct cellule *suivant;    /* ADDED struct - make C++ code into C code */
    } cellule, *liste;
    
    
    liste nouveau()
    {
        return NULL;
    }
    
    liste suivant(liste p)
    {
        return (p->suivant);
    }
    
    int debut(liste l)
    {
        return l->info;
    }
    
    void afficher(liste tete)
    {
        liste p;
        p = tete;
        printf("\n\n");
        printf("\n-----------------------------------------------------\n");
        while (p != NULL) {
            printf(" %d", p->info);
            p = suivant(p);
        }
        printf("\n-----------------------------------------------------\n");
    }
    
    liste ajoutfin(liste l, int a)
    {
        /* liste p1, p2; - REMOVED USELESS VARS */
        liste N = malloc(sizeof(cellule));  /* REMOVE CAST, USE CORRECT TYPE */
        if (N != NULL) {
            N->info = a;
            N->suivant = l;         /* USE parameter to link into existing list */
        }
        return N;                   /* ADDED THIS */
    }                               /* ADDED THIS */
    
    liste remplir_tete(liste p)
    {
        int i;                      /* MOVED FROM for loop, making code C (not C++) */
        int n, a;
    
        printf("Entrer le nombre d'elements de la liste: ");
        scanf("%d", &n);
        for (i = 0; i < n; i++) {
            printf("Entrer l'element %i: \n", i + 1);
            scanf("%i", &a);
            p = ajoutfin(p, a);
        }
        return (p);                 /* MOVED OUTSIDE FOR LOOP !!! */
    }                               /* ADDED THIS */
    
    int main()
    {
        liste l;
        l = nouveau();
        printf("saisie liste 1 --> remplir_tete\n");
        l = remplir_tete(l);
        afficher(l);
        return (0);                 /* SUCCESS IS 0, not 1 */
    }
    And for heavens sake, learn the difference between C and C++
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

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

    Wink thank you

    .................................................. ...............................

    thank you salem for help.........

    no comment !

  11. #11
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104

    hehe, Salem

    Hehe.. Salem isnt making it easy for us noobs

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, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04: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, 05:45 PM