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
|
#include <iostream>
using std::cout;
using std::endl;
using std::ios;
#include <iomanip>
using std::setw;
using std::setiosflags;
#include <cstdlib>
#include <ctime>
typedef struct Carte{
int couleur;
int valeur;
} Carte;
void echange( Carte &, Carte & );
void brasser( Carte [] );
//void afficherJeu( Carte [], const char *[], const char *[] );
const int SIZE = 52;
int main(){
int coul,val,card;
Carte carte;
const char *Couleur[ 4 ] = {"coeur", "carreau", "trèfle", "pique"};
const char *Valeur[ 13 ] = {"As", "Deux", "Trois", "Quatre", "Cinq", "Six", "Sept", "Huit", "Neuf", "Dix", "Valet", "Dame", "Roi"};
cout << *Valeur <<"\n";//ici tt va bien
Carte jeu[ SIZE ] = { 0 };
for ( coul = 0, card = 0; coul < 4; ++coul, ++card)
for (val = 0; val < 13; ++val, ++card){
carte.couleur = coul;
carte.valeur = val;
jeu[ card ] = carte;
}
cout << *Couleur << "\n"; //ici tt va bien (a tester en mettant en comm. la ligne du dessous)
cout << *Valeur<< "\n";//Ici erreur de segmentation!!!
brasser(jeu);
cout << jeu[32].couleur << endl;
for (int i = 0; i < SIZE; i++)
cout << setw(4) << resetiosflags (ios::left) << Couleur[ jeu[ i ].couleur]<< " " ;//<< " de " << Couleur[ jeu[ i ].couleur ] <<"\n";
cout << endl;
return 0;
}
void echange(Carte &c1, Carte &c2){
Carte tmp;
tmp = c1;
c1 = c2;
c2 = tmp;
}
void brasser(Carte jeu[]){
int compteur = 0,i,j;
srand(time(0));
while (++compteur < 100){
i = rand() % 52;
j = rand() % 52;
echange(jeu[i],jeu[j]);
}
} |
Partager