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 de tableau


Sujet :

C++

  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2016
    Messages : 1
    Par défaut Problème de tableau
    Alors voilà j'ai un gros soucis avec mon code. Je ne comprends pas pourquoi mon programme plante au niveau de la création du tableau de la montagne... Est-ce que quelqu'un pourrait m'aider s'il vous plaît ?

    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
    #include <iostream>
    #include "econio.h"
    #include <ctime>
     
    using namespace std;
     
    /****************************************
     **   Structures et variables globales            **
     ****************************************/
    int GNA_nbr=0;
    /****************************************
     **       Prototype des fonctions                   **
     ****************************************/
    void AfficherCiel(int* tab_Ciel, int taille);
    void AfficherSol(int* tab_Sol, int taille);
    //void AfficherMontagne(int* tab_Montagne, int taille);
    int* CreationCiel(int n);
    int* CreationSol(int n);
    int* CreationMontagne(int n);
     
     /****************************************
      **       Programme principal                       **
      ****************************************/
     
     int main ()
     {
         int* tab_Sol=NULL;
         int* tab_Ciel=NULL;
         int* tab_Montagne=NULL;
         int n=80;
         CreationCiel(n);
         AfficherCiel(tab_Ciel, n);
         CreationSol(n);
         AfficherSol(tab_Sol, n);
         CreationMontagne(n);
         //AfficherMontagne(tab_Montagne,n);
     }
     
     /****************************************
      **       Énoncé des fonctions                       **
      ****************************************/
    void AfficherSol(int* tab_Sol, int taille)
    {
        int* pt;
        for(int i=0;i<6;i++)
        {
            for(pt=tab_Sol;pt<tab_Sol+taille;pt++)
            {
                textbackground(GREEN);
                cout << " ";
            }
        }
    }
     
    void AfficherCiel(int* tab_Ciel, int taille)
    {
        int* pt;
        for(int i=0;i<18;i++)
        {
            for(pt=tab_Ciel;pt<tab_Ciel+taille;pt++)
            {
                textbackground(BLUE);
                cout << " ";
            }
        }
    }
     
    /*void AfficherMontagne(int* tab_Montagne, int taille)
    {
        int* pt;
     
    }*/
     
    int* CreationSol(int n)
    {
        int* pt;
        int* tab_Sol;
        tab_Sol=(int*)calloc(n,sizeof(int));
        return tab_Sol;
    }
     
    int* CreationCiel(int n)
    {
        int* pt;
        int* tab_Ciel;
        tab_Ciel=(int*)calloc(n,sizeof(int));
        return tab_Ciel;
    }
     
    int* CreationMontagne(int n)
    {
        int* pt;
        int* tab_Montagne;
        if(GNA_nbr==0)
        {
            srand((unsigned)time(NULL));
            GNA_nbr++;
        }
        for(int i=0; i<n;i++)
            *pt=rand()%18;
        return tab_Montagne;
    }

  2. #2
    Expert confirmé

    Inscrit en
    Août 2006
    Messages
    3 966
    Détails du profil
    Informations forums :
    Inscription : Août 2006
    Messages : 3 966
    Par défaut
    Bonjour,

    Relis ta fonction, et tu trouveras.

  3. #3
    Expert confirmé
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Décembre 2015
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 1 599
    Par défaut
    Bonjour,

    c'est quoi le pointeur non initialisé qui est dans les fonctions CreateXXXX() ?
    int *pt;
    Heureusement que tu ne l'utilises pas, ah oui sauf dans la fonction qui plante...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Débutant en Javascript : problème de tableau !
    Par bluheim dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 06/11/2005, 15h03
  2. [XHTML] problème de tableau
    Par virgul dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 28/04/2005, 07h18
  3. Problème de tableau
    Par tom06440 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 3
    Dernier message: 26/04/2005, 20h30
  4. Problème de tableau
    Par krfa1 dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 08/02/2005, 11h09

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