Bonjour,

Alors, voilà je sollicite votre aide pour un programme que je n'arrive pas à boucler : /


Description :

il s'agit ici de réaliser un sondage sous forme d'enregistrement regroupant :

-le nom

-le prénom

-l'âge

-le sexe

-le choix ( 5 titres parmi 50 ( les titres sont représentés par des numéros )

de la personne sondé

Ensuite de classer les titres celons leurs popularités et d'afficher le top 3.

Et finalement de permettre à l'utilisateur de savoir pour un titre donné sa position ainsi que le nom , le prénom , l'âge et le sexe des personnes qui l'ont choisie en 1er choix.


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
typedef struct personne

{	char sexe;
	int  age;
	char * nom;
	char * prenom;
	int *  choix;
} tpersonne;

//=======================================================================================
{
    tpersonne * la_personne_allouee;
    la_personne_allouee = (tpersonne *)malloc(sizeof(tpersonne));    
       if(la_personne_allouee == NULL)
       {
        printf("\nImpossible d'allouer en memoire le type personne\n");
        return NULL;
       }
   return la_personne_allouee; 
}
 
 char * Saisie_Nom()
{
             char nom_tmp[30];
             int nbr_caractere; 
             char * nom_a_renvoyer; 
             
            printf("\nSaisir le nom de la personne :\n");
            scanf("%s", nom_tmp);
            nbr_caractere = strlen(nom_tmp);
            nom = Alloue_Nom(nbr_caractere);          
            return nom;
     }

 char *  Alloue_Nom(int nbr_caractere){
           char * nom;
           nom = (char *)malloc(sizeof(char * nbr_caractere));
          return nom;
}

//======================================================================================

char * Saisie_Prenom()
{
             char prenom_tmp[30];
             int nbr_caractere; 
             char * prenom_a_renvoyer; 
             
            printf("\nSaisir le prenom de la personne :\n");
            scanf("%s", prenom_tmp);
            nbr_caractere = strlen(prenom_tmp);
            prenom = Alloue_Prenom(nbr_caractere);          
            return prenom;
     }

 char *  Alloue_Prenom(int nbr_caractere){
           char * prenom;
           prenom = (char *)malloc(sizeof(char * nbr_caractere));
          return prenom;
}

//========================================================================================================================================

char * Saisie_Age()
{
             int age_tmp[30];
             int nbr_chiffre; 
             int * age_a_renvoyer; 
             
            printf("\nSaisir l'âge de la personne :\n");
            scanf("%s", age_tmp);
            nbr_chiffre = strlen(age_tmp);
            age = Alloue_Age(nbr_chiffre);          
            return nom;
     }

 char *  Alloue_Age(int nbr_caractere){
           int * age;
           age = (char *)malloc(sizeof(int * nbr_chiffre));
          return age;
}

//========================================================================================================================================

char * Saisie_Sexe()
{
             char sexe_tmp[30];
             int nbr_caractere; 
             char * sexe_a_renvoyer; 
             
            printf("\nSaisir le sexe de la personne :\n");
            scanf("%s", sexe_tmp);
            nbr_caractere = strlen(sexe_tmp);
            sexe = Alloue_Nom(nbr_caractere);          
            return sexe;
     }

 char *  Alloue_Sexe(int nbr_caractere){
           char * sexe;
           sexe = (char *)malloc(sizeof(char * nbr_caractere));
          return sexe;
}

//========================================================================================================================================

char * Saisie_Choix()
{
             int choix_tmp[30];
             int nbr_chiffre; 
             int * choix_a_renvoyer; 
             
            printf("\nSaisir le choix de la personne :\n");
            scanf("%s", choix_tmp);
            nbr_chiffre = strlen(choix_tmp);
            choix = Alloue_Choix(nbr_chiffre);          
            return choix;
     }


 char *  Alloue_Choix(int nbr_caractere){
           int * choix;
           choix = (char *)malloc(sizeof(int * nbr_chiffre));
          return choix;

}

//========================================================================================================================================
void saisie (tpersonne t[], int n) 
{
int i;
int j;
for (i=0;i<n;i++)
 {
  printf("votre nom?\n");
  gets (t[i].nom);
  printf("votre prenom?\n");
  gets (t[i].prenom);
  printf("votre sexe?\n");
  gets (t[i].sexe);
  printf("votre age?\n");
  scanf("%i",&t[i].age); 
  for (j=0;j<5;j++)
  {
   printf("quelle est votre choix?\n");
   scanf("%i",t[j].choix);
  }
 gets(s);
 }
}
//========================================================================================================================================

float titreposition ( tpersonne t[], int titre, int position, int n) /* pour savoir combien de fois tel titre a été cité en tel dans le sondage */
{
int i;
int cpt=0;
for (i=0;i<n;i++)
 {
  if (t[i].choix[position-1] == titre) 
  {
   cpt=cpt+1;
  }
 }
return cpt;
}

//========================================================================================================================================

void calculpop (tpersonne t[] , int t1[50], int n  ) /* Classement des titres les plus cités*/
{
int i;
int j;
int titre;
const int point[5]={1,2,3,4,5};
for (i=0;i<50;i++)
{
 t1[i]=0;
}
for (i=0;i<n;i++)
{
 for(j=0;j<5;j++)
 {
  titre=t[i].choix[j]; 
  t1[titre-1]=t1[titre-1]+point[j];
 }
}
}

//========================================================================================================================================

float indiceplusgrand(int pop[], int n) /* Classe les titres du plus cités au moin cités*/
{
int i;
int imax=0;
for (i=0;i<n;i++)
 {
  if (pop[i]>pop[imax])
  {
   imax=i;
  }
 }
return imax;
}

//========================================================================================================================================

void top3 ( int pop[], int pop3[3], int n ) /* top 3 des titres du sondage*/
{
int i;
for (i=0;i<n;i++)
{
pop3[i]=indiceplusgrand(pop, n);
 pop[pop3]=0;
 }
}
//========================================================================================================================================
int main () /* Action principale*/
{
int pop[50];
int pop3[3];
int position;
int titre;
int nb;
tpersonne * lib; 
tpersonne * sond; 
lib=(tpersonne*)malloc(nb*sizeof(tpersonne));
saisie (sond,nb);
calculpop (sond,pop,nb);
top3 (sond,pop3,nb);
printf("Recherche d'un titre en position donnée\n");
printf("entrez un titre");
scanf("%i",&titre);
printf("entrez la position du titre\n");
scanf("%i",&position);
printf("le titre %i",titre," à été cité %i", titreposition(sond,titre,pop,nb),"en position %i",position);
return 0;
}





Néanmoins lorsque je compile j'ai plusieurs erreurs mais je ne vois pas lesquelles
Si quelqu'un peut m'aider je le remercie d'avance