Progammation en c,

Résolu
masuanga - 19 mars 2013 à 03:02
BunoCS Messages postés 15472 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 25 mars 2024 - 19 mars 2013 à 09:56
bonjour chers membres, voici mon code de gestion des fichiers personnes,je vous demande de m'aider :à modifier les données du dernier enregistrement,la suppression du dernier enregistrement,ainsi que l'affichage des enregistrement c'est dire acces au premier,au précédent,au suivant ou au dernierselon la demande de l'utilistaeur. voici le code:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct Personne
{
char Nom[30];
char Pre[30];
int Age;
char Loc[12];
} PERSONNE;

void AffichePers(PERSONNE *pP)
{
printf("\nNom : %s",pP->Nom);
printf("\nPrenom : %s",pP->Pre);
printf("\nAge : %d",pP->Age);
printf("\nLocalite : %s",pP->Loc);
printf("\n");
return;
}

main()
{
FILE *Fichier;
PERSONNE P;
char NomFichier[80];
char NomPers[30];
int Choix;
printf("\n\nChemin et nom du fichier des personnes ? ");
gets(NomFichier);
if ((Fichier = fopen(NomFichier,"a+")) != NULL)
{
do
{
printf("\n- 1 - Ajout d'une personne");
printf("\n- 2 - Lecture de tout le fichier");
printf("\n- 3 - Recherche d'une personne");
printf("\n- 0 - Fin");
printf("\n\n----> Votre choix ? ");
scanf("%d", &Choix);
getc(stdin);
switch(Choix)
{
case 1 : printf("\nNom : ");
gets(P.Nom);
if (strlen(P.Nom) > 0)
{
printf("Prenom : ");
gets(P.Pre);
printf("Age : ");
scanf("%d",&P.Age);
getc(stdin);
printf("Localite : ");
gets(P.Loc);
fprintf(Fichier, "%s %s %d %s\n", P.Nom, P.Pre, P.Age, P.Loc);
}
break;
case 2 : rewind (Fichier);
while ((fscanf(Fichier, "%s%s%d%s", P.Nom, P.Pre, &P.Age, P.Loc)) != EOF)
{
AffichePers(&P);
system("pause");
}
break;
case 3 : printf("\nNom de la personne recherchee : ");
gets(NomPers);
if (strlen(NomPers) > 0)
{
rewind (Fichier);
while ((fscanf(Fichier, "%s%s%d%s", P.Nom, P.Pre, &P.Age, P.Loc)) != EOF)
{
if (strcmp(NomPers, P.Nom) == 0)
{
AffichePers(&P);
break;
}
}
}
break;
case 0 : printf("\n\nBye ...");
break;
}
} while(Choix != 0);
fclose(Fichier);
}
printf("\n\n");
system("pause");
return 0;
}

merci d'avance

1 réponse

BunoCS Messages postés 15472 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 25 mars 2024 103
19 mars 2013 à 09:56
Hello,
Qu'est-ce qui te bloque?


@+
Buno, Admin CS
L'urgent est fait, l'impossible est en cours. Pour les miracles, prévoir un délai...
3
Rejoignez-nous