Bonjour à tous, j'ai un problème dans un de mes programmes.
Je suis étudiant en informatique et je doit réaliser l'exercice suivant.
Encoder le Nom et le Prénom d'ouvrier et les stocker dans un fichier.
Il faut trier l'affichage dans l'ordre Alphabétique et le fichier doit être organiser de manière séquentielle logique, donc je dois créer un algorithme de chaînage.
Je suis parvenus à commencé cet algorithme mais je suis bloqué et je ne vois pas comment réaliser les opérations qu'il me manques.
Mon problème survient dans la fonction "Chainage" , je ne cherche pas à avoir la solution de fin du code, j'aimerais juste qu'on m'aiguille vers les opération à effectuer.
Merci d'avance.

Voici le code de mon programme, je n'ai pas encore mis le Header des fonctions.

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
#include<stdio.h>
#include<windows.h>
#include<conio.h>
 
void Remplir(struct contact[] , int, long*);
void Display(struct contact*, int);
void Chainage(struct contact[], long*, int);
 
struct contact
{
	char Nom[20];
	char Prenom[20];
	long svt;
};
 
void main()
{
	long pto=-1;
	int choix, nbf=0;
	int quit=0;
	char confirm;
	struct contact fiche[100];
 
	do
	{
		do
		{
			printf("\nMenu du programme");
			printf("\n-----------------");
 
			printf("\nAppuyer sur 1 pour ajouter une fiche contact");
			printf("\nAppuyer sur 2 pour afficher la liste des contact");
			printf("\nAppuyer sur 3 pour supprimer le fichier[Contact.dat]");
			printf("\nAppuyer sur 4 pour quitter l'application");
			printf("\nVotre choix: ");
			fflush(stdin);
			scanf("%d",&choix);
			if(choix<1||choix>4)
				printf("\nErreur de saisie!");
		}while(choix<1||choix>4);
 
		switch (choix)
		{
		case 1:
 
			printf("\nAjout d'un ouvrier");
			printf("\n------------------");
			Remplir(fiche, nbf,&pto);
			nbf++;
			break;
		case 2:
			printf("\nAffichage des fiches");
			printf("\n--------------------");
 
			Display(&fiche[0], nbf);
			system("pause");
			break;
		case 3:
			do
			{
				printf("\nEtes-vous sur de vouloir supprimer le fichie ?(o/n): ");
				fflush(stdin);
				scanf("%c",&confirm);
				if(confirm!='o'&& confirm!='n')
					printf("\nErreur de saisie!");
			}while(confirm!='o'&& confirm!='n');
 
			switch (confirm)
			{
			case ('o'):
				remove("contact.dat");
				printf("\nFichier supprime");
				break;
			case ('n'):
				printf("\nSuppression annulee");
				break;
			}
			break;
		case 4:
			printf("\nAu revoir");
			quit=1;
			break;
		}
	}while(quit!=1);
}
 
void Remplir(struct contact fiche[], int nb, long *pto)
{
	FILE *fp;
	fp=fopen("contact.dat","ab");
 
	fwrite(pto,sizeof(long),1,fp);
	printf("\nEntrez le nom du contact: ");
	fflush(stdin);
	fgets(fiche[nb].Nom,20,stdin);
 
	printf("\nEntrez le prenom du contact: ");
	fflush(stdin);
	fgets(fiche[nb].Prenom,20,stdin);
 
	Chainage(fiche, pto, nb);
	fclose(fp);
}
 
void Display(struct contact *pf, int nb)
{
	int i=0;
	int out;
	int dep=0;
	int exist=0;
	FILE *fp;
	fp=fopen("contact.dat","rb");
 
 
	if(fp==((FILE *)NULL))
	{
		printf("\nErreur d'ouverture du fichier");
		printf("\nFichier inexistant!");
		exist=1;
	}
	out=0;
	fseek(fp,sizeof(long),SEEK_SET);
	fread(pf,sizeof(struct contact),1,fp);
	printf("\nNom: %s",pf->Nom);
	printf("\nPrenom: %s",pf->Prenom);
	printf("\nSvt: %ld\n",pf->svt);
	fclose(fp);
}
 
void Chainage(struct contact fiche[], long *pto,int nbo)
{
	int valid=0;
	FILE *fp;
	fp=fopen("contact.dat","w+b");
	struct contact *prec;
 
	if(*pto==-1)
	{
		fiche[0].svt=-1;
		fseek(fp,2*sizeof(long),SEEK_SET);
		fwrite(&fiche[0],sizeof(struct contact),1,fp);
		*pto=0;
	}
	else
	{
		fseek(fp,2*sizeof(long)+*pto*sizeof(struct contact),SEEK_SET);
		fread(prec,sizeof(struct contact),1,fp);
 
		while(*prec!=-1);
		{
 
		}
	}
	rewind(fp);
	fwrite(pto,sizeof(long),1,fp);
	fclose(fp);
}