Bonjour,

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
struct structure_student {
	char name[50];
	int size;
	bool sex; //sex=0 it's a boy -- sex=1 it's a girl
};
 
//****** function exchangeStudent *****
//* use to exchange the position of 2 students in a table of structure_student
void exchangeStudent(structure_student* studentS, int a, int b)
{
	structure_student temp;
//put the data of the student a into the temp
	strcpy(temp.name, studentS[a].name);
	temp.size=studentS[a].size;
	temp.sex=studentS[a].sex;
//put the data of the student b into the data of the student b
	strcpy(studentS[a].name, studentS[b].name);
	studentS[a].size=studentS[b].size;
	studentS[a].sex=studentS[b].sex;
//put the data of the temp into the data of the student b
	strcpy(studentS[b].name, temp.name);
	studentS[b].size=temp.size;
	studentS[b].sex=temp.sex;
}
Ma fonction exchangeStudent marche très bien si je l'appel une dizaine de fois mais si je l'appelle quelque chose comme 200 fois, et ben Segmentation Fault !!!

Alors je comprend pas, peut être que mon "structure_student temp" ne de détruit pas à chaque foi, du coup il reste en mémoire ?

Faut-il le déclarer en dynamique, puis le détruire ?
et alors comment faire ?

Merci pour toute réponse