IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

problème des tableaux dynamiques (tas)


Sujet :

C

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Architecte de système d'information
    Inscrit en
    Avril 2009
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : Serbie

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Avril 2009
    Messages : 9
    Points : 0
    Points
    0
    Par défaut problème des tableaux dynamiques (tas)
    salut a tt

    Voici le problème d'un grand débutant en C:
    Je commence par créer un tableau dynamique pour implémente la structure de tas voila mon code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    #include <stdio.h>
    #include <stdlib.h>
     
     typedef struct Tas *PTasmax;
        typedef struct Commande * PCommande;
     
        typedef struct Commande
        {
                int unsigned NCommande;
                char DateCommande[11];
                int unsigned NumClient;
                char NomClient[25],PrenomClient[25];
                char AdresseClient[25];
                int unsigned QuantiteCommande;
                char etat;
     
        }Commande;
        typedef struct Tas
        {
                int ind;
                PCommande T;
        }Tas;
     
     
     
     
    void AfficherTas(PTasmax T)
        {
                int i;
        for(i=0;i<=T->ind;i++)
                {
     
                        printf("\n  -------------------------------------------- ");
                        printf("\n |- Numero Commande : %u",T->T[i].NCommande);
                        printf("\n |- Quantite Commande : %u",T->T[i].QuantiteCommande);
                        printf("\n |- Date de Commande Client : %s ",T->T[i].DateCommande);
                        printf("\n |- Numero Client : %u ",T->T[i].NumClient );
                        printf("\n |- Nom Client : %s ",T->T[i].NomClient);
                        printf("\n |- Prenom Client : %s ",T->T[i].PrenomClient);
                        printf("\n |- Adress Client : %s ",T->T[i].AdresseClient);
                        printf("\n  -------------------------------------------- ");
                }
        }
     
     
     
    int Pere(int Pos,PTasmax Tasmax){
    div_t temp;
    temp =  div(Pos,2);
    if(Pos % 2 ==0)
    {return ((temp.quot)-1);}
    else
    {return (temp.quot);}
    }
     
    int Qcommande(int Pos,PTasmax Tasmax){return Tasmax->T[Pos].QuantiteCommande;}
     
     
    void  Echanger(int index1,int index2,PTasmax Tmax)
    {
    Commande c;
    c = Tmax->T[index1];
    Tmax->T[index1] = Tmax->T[index2];
    Tmax->T[index2] = c;
    }
     
    void EntasserTmax(int i,PTasmax Tmax){
    int g,d,m;
     
    g = 2*i+1;
    d = 2*i+2;
    m = i;
     
    if(g<=Tmax->ind && Qcommande(g,Tmax)>Qcommande(m,Tmax))
    {
        m = g;
    }
    if(d<=Tmax->ind && Qcommande(d,Tmax)>Qcommande(m,Tmax))
    {
        m = d;
    }
    if(m != i)
    {
        Echanger(i,m,Tmax);
        EntasserTmax(m,Tmax);
    }
     
    }
     
     
     
     
     
     
     
     
     
    void InsererTmax(Commande V,PTasmax Tasmax)
    {
        int i,p;
       i = Tasmax->ind;
    p = Pere(i,Tasmax);
    while(i>0 && V.QuantiteCommande > Qcommande(p,Tasmax))
    {
    Tasmax->T[i] = Tasmax->T[p];
    i = p;
    p = Pere(i,Tasmax);
    }
    Tasmax->T[i] = V;
    }
     
    void ajoutetasmax(PTasmax Tasm){
     
         if(Tasm->T == NULL)
        {
        Tasm->ind = Tasm->ind+1;
     
        //Tasm->T = malloc(sizeof(Commande));
    //T->T = realloc(T->T,1 * sizeof(Commande));
        Tasm->T = calloc(1,sizeof(Commande));
        }else
        {
    Tasm->ind = Tasm->ind+1;
    Tasm->T = realloc(Tasm->T,Tasm->ind+1 * sizeof(Commande));
        }
     
     
     
     
    printf(" \n Entre Nom Client : %d ",Tasm->ind);
                        scanf("%s",&Tasm->T[Tasm->ind].NomClient);
                printf(" \n Entre Prenom Client : %d ",Tasm->ind);
                                        scanf("%s",&Tasm->T[Tasm->ind].PrenomClient);
    									    printf("\n |- Numero Client : ");
      scanf("%u",&Tasm->T[Tasm->ind].NumClient);
     
      printf("\n |- Numero Commande : ");
      scanf("%u",&Tasm->T[Tasm->ind].NCommande);
         printf("\n |- Quantite Commande :");
      scanf("%u",&Tasm->T[Tasm->ind].QuantiteCommande);
        printf("\n |- Date de Commande Client : ");
      scanf("%s",&Tasm->T[Tasm->ind].DateCommande);
     
     
         printf("\n |- Adress Client : ");
      scanf("%s",&Tasm->T[Tasm->ind].AdresseClient);
     
     
     
    }
     
     void ajouteT(PTasmax Tasm){
    Commande V;
    // SAISIE DE LA COMMANDE
    printf(" \n Entre Nom Client : ");
    scanf("%s",&V.NomClient);
     
    printf(" \n Entre Prenom Client : ");
    scanf("%s",&V.PrenomClient);
     
    printf("\n |- Numero Client : ");
    scanf("%u",&V.NumClient);
     
    printf("\n |- Numero Commande : ");
    scanf("%u",&V.NCommande);
     
    printf("\n |- Quantite Commande :");
    scanf("%u",&V.QuantiteCommande);
     
    printf("\n |- Date de Commande Client : ");
    scanf("%s",&V.DateCommande);
     
    printf("\n |- Adress Client : ");
    scanf("%s",&V.AdresseClient);
    V.etat = 'c';
    //FIN DE LA SAISIE
     
     
    //IF
        if(Tasm->T == NULL)
        {
        Tasm->ind = Tasm->ind+1;
     
        //Tasm->T = malloc(1*sizeof(Commande));
    //T->T = realloc(T->T,1 * sizeof(Commande));
        Tasm->T = calloc(1,sizeof(Commande));
        }else
        {
    Tasm->ind = Tasm->ind+1;
    Tasm->T = realloc(Tasm->T,Tasm->ind+1 * sizeof(Commande));
        }
    //END IF
     
    //INSERTION PAR LA PROCEDURE INSERERTMAX
    InsererTmax(V,Tasm);
    //FIN INSERTION
        }
     
    void PagePrincipale();
     
    int main()
    {
    PTasmax Tasm;
     
     
    int i;
      Tasm = (PTasmax)malloc(sizeof(Tas));
                Tasm->T = NULL;
                Tasm->ind = -1;
     
     
     
     
    ajouteT(Tasm);
    ajouteT(Tasm);
    ajouteT(Tasm);
    AfficherTas(Tasm);
     
     
     
     
     
    return 0;
     
    }
     
     
     
     
     
     
    void PagePrincipale()
    {
        int j;
        system("cls");
    		printf("|----------------------------------------------------------------------------|\n");
    		printf("|[1]- Saisir d'une ou de plusieurs Commandes .                               |\n");
    		printf("|[2]- Afficher les info de la commande qui contient la plus grande quantite .|\n");
    		printf("|[3]- La Modification de la quantite commandee d'une commande .              |\n");
    		printf("|[4]- Afficher le nombre de commandes en attente de traitement .             |\n");
    		printf("|[5]- Afficher de la quantite totales des commandes en attente de traitement.|\n");
    		printf("|[6]- Afficher de la liste des commandes .                                   |\n");
    		printf("|[7]- Sortir Du Programme .                                                  |\n");
    		printf("|----------------------------------------------------------------------------|\n");
    		for(j=0;j<=7;j++){ printf("\n"); }
    		printf("                         Programmer Par : Oussama Abdellah. \n");
    }

    alors si j’exécute ce code la il exécuté bien sans erreur sauf a la dernière commande le programme bloque


    si j’exécute le code par une seule appel de la fonction d'insertion
    le programme fonction bien

    Aide moi SVP

  2. #2
    Nouveau Candidat au Club
    Profil pro
    Architecte de système d'information
    Inscrit en
    Avril 2009
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : Serbie

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Avril 2009
    Messages : 9
    Points : 0
    Points
    0
    Par défaut
    Ya Quelqu’un !!!

  3. #3
    Membre émérite
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2011
    Messages
    1 255
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2011
    Messages : 1 255
    Points : 2 627
    Points
    2 627
    Par défaut
    Citation Envoyé par oussaki Voir le message
    alors si j’exécute ce code la il exécuté bien sans erreur sauf a la dernière commande le programme bloque
    je ne vois aucune commande, je vois juste 3 insertions et un affichage.

    Ton code est difficile à lire avec les indentations n'importe comment.

    Que cherches-tu à faire ? parce que tes fonctions sont très brouillon.

  4. #4
    Membre confirmé
    Femme Profil pro
    Développeur Java
    Inscrit en
    Décembre 2009
    Messages
    236
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2009
    Messages : 236
    Points : 491
    Points
    491
    Par défaut
    Peux tu nous transmettre ton erreur, il sera alors plus simple d'en chercher la source

  5. #5
    Nouveau Candidat au Club
    Profil pro
    Architecte de système d'information
    Inscrit en
    Avril 2009
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : Serbie

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Avril 2009
    Messages : 9
    Points : 0
    Points
    0
    Par défaut
    Bin merci de votre rep

    Oui ya 3 appel
    ajouteT(Tasm);
    ajouteT(Tasm);
    ajouteT(Tasm);

    Si vous essayez le code , vous remarquerez l'apparition de problèmes dans la fin de l'appel 3 de la fonction ajouteT();

    Si je fait une seule appel de la fonction ajouteT(Tasm);
    le programme fonctionne bien

    http://pastebin.com/cuCzvdgz

    Essayez avec ça

  6. #6
    Nouveau Candidat au Club
    Profil pro
    Architecte de système d'information
    Inscrit en
    Avril 2009
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : Serbie

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Avril 2009
    Messages : 9
    Points : 0
    Points
    0
    Par défaut
    Avec 3 appel de la fonction ajouteT


    et

    mais avec une seule appel de la fonction ajouteT dans le main

    le programme l’exécute sans erreur


  7. #7
    Membre émérite
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2011
    Messages
    1 255
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2011
    Messages : 1 255
    Points : 2 627
    Points
    2 627
    Par défaut
    tu as des problème d'allocation mémoire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Tasm->T = realloc(Tasm->T,Tasm->ind+1 * sizeof(Commande));
    ce code alloue n'importe quoi !!! la taille est de Tasm->ind + sizeof(Commande) !!! il y a un problème de parathèse !!
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Tasm->T = realloc(Tasm->T,(Tasm->ind+1) * sizeof(Commande));
    Principe de base, la multiplication (division) est "prioritaire" sur l'addition (soustraction)

  8. #8
    Nouveau Candidat au Club
    Profil pro
    Architecte de système d'information
    Inscrit en
    Avril 2009
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : Serbie

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Avril 2009
    Messages : 9
    Points : 0
    Points
    0
    Par défaut
    Citation Envoyé par mala92 Voir le message
    tu as des problème d'allocation mémoire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Tasm->T = realloc(Tasm->T,Tasm->ind+1 * sizeof(Commande));
    ce code alloue n'importe quoi !!! la taille est de Tasm->ind + sizeof(Commande) !!! il y a un problème de parathèse !!
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Tasm->T = realloc(Tasm->T,(Tasm->ind+1) * sizeof(Commande));
    Principe de base, la multiplication (division) est "prioritaire" sur l'addition (soustraction)



    Merci beaucoup
    Je n'ai pas trouvé les mots pour vous remercier

    Je vous souhaite du succès dans votre vie

Discussions similaires

  1. Réponses: 6
    Dernier message: 20/02/2007, 17h00
  2. libération des tableaux dynamiques
    Par franckgar dans le forum Langage
    Réponses: 4
    Dernier message: 19/04/2006, 20h49
  3. permutations/combinaisons sur des tableaux dynamiques
    Par pEAk230 dans le forum Langage
    Réponses: 5
    Dernier message: 19/04/2006, 13h18
  4. Problème avec tableaux dynamiques et procédure
    Par K20 dans le forum Langage
    Réponses: 11
    Dernier message: 06/01/2006, 20h51
  5. [D2005]Problème de tableaux dynamique
    Par Laurent Dardenne dans le forum Delphi .NET
    Réponses: 8
    Dernier message: 26/07/2005, 11h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo