Bonjour,
j'ai écris un morceau de code "idiot" pour comprendre comment alloue des (structures) listes chaines et avec un accès a c'est dernière mais ca bug dans certaine condition des que j'accède a une 4 unité ou + on se retrouve avec un accès violation donc soit j'ai mal alloue la mémoire écrasement de pointeur dans les liste soit c'est l'accès que j'ai mal écris.
voila le code (il n'y a pas d'erreur a la compilation seulement a l'exécution)

structure2.c
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
 
#include<stdio.h>
#include<stdlib.h>
#include<stddef.h>
#include"struct1.h"
 
UNIT* (*select)(void);
 
void cree_unit(void){
 
 
	int instance_unit=0;
 
	printf("combien d'unit ? \n");
	scanf("%i",&nb_unit);
 
	if (nb_unit>=1){
		Tete=NULL;
		Nouveau=(UNIT*)malloc(sizeof(UNIT));
		if (Nouveau==NULL){
			printf("allocation malloc ln25");
			exit(EXIT_FAILURE);
		}
		Nouveau->pSuivant = Tete;
		Tete = Nouveau;
 
		if (Tete != NULL) {
			pCourant = Tete;
			while (pCourant->pSuivant != NULL) pCourant = pCourant->pSuivant;
 
			if (nb_unit>=2){
				for(instance_unit;instance_unit<nb_unit;instance_unit++){
					Nouveau = (UNIT*)malloc(sizeof(UNIT));
					if (Nouveau==NULL){
						printf("allocation malloc ln39");
						exit(EXIT_FAILURE);
					}
					pCourant->pSuivant = Nouveau;
					Nouveau->pSuivant = NULL;
 
				}
 
			}
		}
	}
	if(nb_unit==0){
		printf("vous n'avez cree aucune unité \n");
		return;
	}
}
UNIT*(selection_unit)(void){
	int select_unit=0;
	int tete_unit=2;
 
 
	printf("selectionner une unit ");
	scanf("%i",&select_unit);
	if (select_unit>nb_unit){
		printf ("erreur selection unit > au nb unit\n");
		exit(EXIT_FAILURE);
	}
 
	if (select_unit==0){ 
		base_st=Tete;
		printf("unit %i \n",select_unit);
		return base_st;
	}
	if (select_unit==1){ 
		base_st=Tete;
		base_st=base_st->pSuivant;
		printf("unit %i \n",select_unit);
		return base_st;
	}
	else {
		base_st=Tete;
		for(tete_unit;tete_unit<select_unit;tete_unit++){
			base_st=base_st->pSuivant;
		}
		printf("unit %i \n",select_unit);
		return base_st;
	}
}
void emplacement_unit(UNIT* select){
 
 
	printf("\n indiquer position x ");
	scanf("%i",&(select->x));
 
	printf("\n indiquer position y ");
	scanf("%i",&(select->y));
 
	printf("\n indiquer angle ");
	scanf("%i",&(select->angle));
 
	return;
	}
 
void detruire_allunit(){
	int instance_unit=2;
 
 
 
	if (nb_unit==1){
 
 
		free(Tete);
		return;
		}
 
 
 
 
	if (nb_unit>=2){
		Destruct=Tete;
		Destruct=Tete->pSuivant;
		free(Tete);
		for(instance_unit;instance_unit<nb_unit;instance_unit++){
			Destruct2=Destruct->pSuivant;
			free(Destruct);
 
 
		}
 
 
	}
 
 
 
}
 
 
 
 
void main(){
 
	printf("hello ");
	cree_unit();
	if (nb_unit>=1){
		emplacement_unit(selection_unit());
	}
	detruire_allunit();
	exit(EXIT_SUCCESS);
 
 
}
struct1.h
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
 
typedef struct unit UNIT;
struct unit {
		int x;
		int y;
		int angle;
		UNIT *pSuivant;	
	};
	UNIT * pCourant;
	UNIT *Nouveau;
	UNIT *Destruct;
	UNIT *Destruct2;
	UNIT *Tete;
	UNIT *base_st=NULL;
	int nb_unit=0;
voila merci d'avance pour vos reponse.(compiler avec visual 2010 c++ sur winxp )