j'ai fais mon programme mais quand je compile j'ai une erreur que j'ai jamais vue
voila 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
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
 
typedef struct Personne
{
char nom[16];
char telephone[16];
char adresse[20];
}Personne;
 
 
 
int main()
 
{
int i=0, nbLignes=0, menu = 0;
Personne contact[50];
Personne contactSup;
 
FILE* fichier = NULL;
FILE* fichier1 = NULL;
FILE* fich = NULL;
FILE* fichsup = NULL;
do
{
nbLignes=0;
fichier = fopen("adresse.txt", "r+");
 
if (fichier != NULL)
{
while(fscanf(fichier, "%s %s %s %s\n", contact[nbLignes].nom, contact[nbLignes].telephone, contact[nbLignes].adresse) == 4)
nbLignes++;
 
}
fclose(fichier);
printf("\n\t\t\tC A R N E T  D ' A D R E S S E\n\n\n" );
 
 
printf("1. Ajouter un contact\n" );
printf("2. Afficher tout les contacts\n" );
printf("3. Supprimer un contact\n");
printf("4. Rechercher un contact\n");
printf("5. trier les contacts\n");
 
printf("\n" );
 
 
printf("Votre choix : " );
 
scanf("%ld", &menu);
 
 
 
switch (menu)
 
{
 
case 1 : //ajouter contact
fichier1 = fopen("adresse.txt", "r+");
 
if ((fichier1 != NULL) && (nbLignes < 50))
{
while(fscanf(fichier1, "%s %s %s %s\n", contact[nbLignes].nom, contact[nbLignes].telephone, contact[nbLignes].adresse) == 4)
nbLignes++;
 
if(nbLignes==0)
fseek(fichier1, -1, SEEK_CUR);
 
printf("\nNom : ");
scanf("%s", &contact[nbLignes].nom);
fprintf(fichier1, "%s ", contact[nbLignes].nom);
 
 
printf("Telephone : ");
scanf("%s", &contact[nbLignes].telephone);
fprintf(fichier1, "%s ", contact[nbLignes].telephone);
 
printf("Adresse : ");
scanf("%s", &contact[nbLignes].adresse);
fprintf(fichier1, "%s\n", contact[nbLignes].adresse);
fclose(fichier1);
}
else
{
printf("\nLe carnet d'adresse est plein !!\n\n");
}
break;
 
 
 
case 2 : //afficher contact
fich = fopen("adresse.txt", "r+");
 
if (fich != NULL)
{
nbLignes=0;
while(fscanf(fich, "%s %s %s %s\n", contact[nbLignes].nom, contact[nbLignes].telephone, contact[nbLignes].adresse) == 4)
nbLignes++;
 
for(i=0;i<nbLignes;i++)
{
printf("\nNom: %s\nPrenom: %s\nTelephone: %s\nAdresse: %s\n\n", contact[i].nom, contact[i].telephone, contact[i].adresse);
}
 
if( nbLignes == 0)
{
printf("Il n'y a pas de contact dans le carnet d'adresse !!!\n\n");
}
fclose(fich);
}
 
break;
 
case 3 : //supprimer un contact
 
fichsup = fopen("adresse.txt", "r+");
fichier=fopen("tampon.txt","w");
int i = 0, j = 0;
char supnom[50];
 
printf ("Nom du contact a supprimer ? \n");
scanf ("%s", supnom);
printf("nb ligne = %d",nbLignes);
while(i + j < nbLignes)
{
fscanf(fichsup, "%s %s %s %s\n", contactSup.nom,  contactSup.telephone, contactSup.adresse);
if(strcmp(supnom, contactSup.nom) != 0)
{
fprintf(fichier,"%s ",contactSup.nom);
 
fprintf(fichier,"%s ",contactSup.telephone);
fprintf(fichier,"%s ",contactSup.adresse);
fprintf(fichier,"\n");
i++;
}
else
j++;
}
fclose(fichsup);
fclose(fichier);
fichsup = fopen("adresse.txt", "w");
fichier=fopen("tampon.txt","r");
while(fscanf(fichier, "%s %s %s %s\n", contactSup.nom, contactSup.telephone, contactSup.adresse)==4){
fprintf(fichsup,"%s ",contactSup.nom);
 
fprintf(fichsup,"%s ",contactSup.telephone);
fprintf(fichsup,"%s ",contactSup.adresse);
fprintf(fichsup,"\n");}
fclose(fichsup);
fclose(fichier);
 
 
break;
 
 case 4 : //rechercher un contact
 
 char buf[30];
 
	printf("Entrer le nom du persone : ");
	fflush(stdin);
	gets(buf);
	printf("\n");
	for(i=0;i<nbLignes;i++)
		if(strcmp(buf,contact[i].nom)==0 )
		 printf("\nNom: %s\nPrenom: %s\nTelephone: %s\nAdresse: %s\n\n", contact[i].nom, contact[i].telephone, contact[i].adresse);
break;
 
case 5:
 
int done;
Personne temp;
 
		 do {
						  done=1;
						  for(i=0;i<nbLignes;i++)
 
						  {  if(contact[i].nom>contact[i+1].nom)
 
										{  temp=contact[i];
 
											contact[i]=contact[i+1];
 
											contact[i+1]=temp;
											done=0;
 
 
										}
 
						  }
 
							} while(done == 0);      printf("Le Tableau est trie.\n\n");
		 break ;
 
}
}while(menu!=5);
 
 
return 0;
 
 
 
	  }
dans la "case 4" j'ai une erreur qui dit : case bypasses initialization of local variable in function main
svp aidez moi et merci d'avance