Bonjour,
Mon problème est que lorsque j'exécute mon code tout se passe comme si le choix était déja en mémoire (?!).
Le switch s'exécute entièrement.
Peut on m'aider à résoudre se problème, svp?
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
/* le tri  strohecker guillaume */
 
#include <stdio.h>
#include <stdlib.h>
#define NB_MAXI_ELEMENT 10000
 
/* fonction echange */
 
void Echange(int *Tablo, int i, int j){
	int temp;
	temp = Tablo[i];
	Tablo[i] = Tablo[j];
	Tablo[j] = temp;
}
 
/* algorithme de tri par sélection */
 
static void TriSelection(int *T, int taille){
	int k, i, imax;
	k = taille - 1;
	while (k > 0){
		/* recherche de l'indice maximum */
		imax = 0;
		for (i = 1; i <= k; i++){
			if (T[imax] < T[i]){
				imax = i;
			}
		}
		/* echange */
		Echange(T, k, imax);
		k--;
	}
}
 
/* Algorithme de tri à bulle */
 
static void TriBulle(int *T, int taille){
	int i, k;
	k = taille - 1;
	/* pour chaque passe */
	while(k > 0){
		/* on fait remonter le plus grand */
		for (i = 1; i <= k; i++){
			if (T[i] < T[i-1]){
				/* échange de T[i-1] et T[i] */
				Echange(T, i, i-1);
			}
		}
		k--;
	}
}
 
/* Algorithme de tri par insertion */
 
static void TriInsertion(int *T, int taille){
	int k, i, v;
	for( k = 1; k < taille; k++)
	{
		v = T[k];
		i = k - 1;
	/* on décale les éléments pour l'insertion */
		while(( i>= 0) && ( v <T[i]))
		{
		T[i+1] = T[i];
		i--;
		}
	/* insertion */
	T[i+1] = v;
	}
}
 
/* fonction de saisie de tableau */
 
int SaisieTableau(int tableau[NB_MAXI_ELEMENT]){
	int taille, i;
	puts("Saisir la taille de votre tableau : ");
	scanf("%d", &taille);
	if(taille > NB_MAXI_ELEMENT){
		puts("Erreur : Le tableau est trop petit");
		exit(1);
	}
	puts("Saisir les valeurs de votre tableau : ");
	for(i = 0; i < taille; i++)
		scanf("%d", &tableau[i]);
	return taille;
}
 
/* fonction d'affichage */
 
void AffichageTableau(int tableau[], int taille){
	int i;
	for(i = 0; i < taille; i++)
		printf("L'element numero %d vaut %d\n", i, tableau[i]);
}
 
 
/* Fonction de choix */
 
void FaitesVotreChoix(int tableau[], int taille){
	char choix ;
	puts("Faites votre choix :");
	puts("Un tri par selection -----> a");
	puts("Un tri a bulle -----------> b");
	puts("Un tri par insertion -----> c");
	puts("Quitter ------------------> d");
	choix = (char) getchar();
	switch(choix){
	case'a' : 
		puts("Avant le tri:");
		AffichageTableau(tableau, taille);
		puts("Après le tri:");
		AffichageTableau(tableau, taille);
		break;
	case'b' : 
		puts("Avant le tri:");
		AffichageTableau(tableau, taille);
		puts("Après le tri:");
		AffichageTableau(tableau, taille);
		break;
	case'c' : 
		puts("Avant le tri:");
		AffichageTableau(tableau, taille);
		puts("Après le tri:");
		AffichageTableau(tableau, taille);
		break;
	case'd' :
		break;
	default : puts("Erreur de saisie!!");
	}
}
 
/* programme test */
 
int main(void){
	int tableau[NB_MAXI_ELEMENT];
	int taille = 0;
	SaisieTableau(tableau);
	FaitesVotreChoix(tableau, taille);
	return 0;
}