- #include <stdio.h> /* printf et scanf bien sur :) */
- #include <conio.h> /*pour getche(); et getch(); */
- #include <string.h> /* pour strcpy */
- typedef struct adresse {int no;char cp[50],rue[50],ville[50];};
- typedef struct personne{char nom[20],prenom[20];
- adresse adre;
- };
- int menu(); /* declaration de fonction */
- void main(void)
- {
- int choix;
- personne e;
- char nom[20],prenom[20]; /* pour la modification */
- char rep;
- FILE *x,*y; /*pointeurs de fichiers x-->pointeur source y-->pointeur cible */
- do
- {
- choix=menu();
- switch(choix)
- {
- /*****************************************************************************/
- case 1:
- x=fopen("Agenda.txt","a+");
- do {
- clrscr();
- printf("Infos de la personne : nom,prenom !");
- scanf(" %s %s",e.nom,e.prenom);
- printf("\n adresse (no de rue,rue,ville,code postal) ?");
- scanf("\n %d %s %s %s",&e.adre.no,e.adre.rue,e.adre.ville,e.adre.cp);
- fwrite(&e,sizeof(personne),1,x);
- printf("\n encore ?o/n");
- rep=getche();
- }while (rep=='o'); /* tant que la reponse est o on execute le do */
- fclose(x);
- break;
-
- /*******************************************************************************/
- case 2:
- clrscr();
- x=fopen("Agenda.txt","r"); /* ouverture du fichier en mode lecture */
- fread(&e,sizeof(personne),1,x);
- while (!feof(x)) /* tant que non fin de fichier */
- {
- printf("\n %s %s",e.nom,e.prenom);
- printf("\n %d %s %s %s",e.adre.no,e.adre.cp,e.adre.rue,e.adre.ville);
- fread(&e,sizeof(personne),1,x);
- }
- fclose(x);
- getch();
- break;
- /*******************************************************************************/
- case 3:
- printf("\n Quel est le nom et le prenom de la personne ?");
- scanf("%s %s",nom,prenom);
-
- x=fopen("Agenda.txt","r+"); /* source */
- y=fopen("Agenda.txt","r+"); /* cible */
-
- fread(&e,sizeof(personne),1,x);
- while (!feof(x)) /* tant que non fin de fichier */
- {
- if (strcmp(nom,e.nom)==0 && (prenom,e.prenom)==0)
- {
- printf("\n nouvelle adresse !?");
- scanf("%d %s %s %s",&e.adre.no,e.adre.cp,e.adre.rue,e.adre.ville);
- }
- fwrite(&e,sizeof(personne),1,y);
- fread(&e,sizeof(personne),1,x);
- }
- fclose(x);
- fclose(y);
- }
- }while(choix!=4);
- }
-
- /*******************************************************************************/
- int menu() /* definition de fontion */
- {
- int choix;
- clrscr();
- printf("\n 1.Création \n 2.Consultation \n 3.Modification 4.Quitter \n");
- scanf("%d",&choix);
- return choix;
- }
- /********************************************************************************/
-
- /* FIn du code */
#include <stdio.h> /* printf et scanf bien sur :) */
#include <conio.h> /*pour getche(); et getch(); */
#include <string.h> /* pour strcpy */
typedef struct adresse {int no;char cp[50],rue[50],ville[50];};
typedef struct personne{char nom[20],prenom[20];
adresse adre;
};
int menu(); /* declaration de fonction */
void main(void)
{
int choix;
personne e;
char nom[20],prenom[20]; /* pour la modification */
char rep;
FILE *x,*y; /*pointeurs de fichiers x-->pointeur source y-->pointeur cible */
do
{
choix=menu();
switch(choix)
{
/*****************************************************************************/
case 1:
x=fopen("Agenda.txt","a+");
do {
clrscr();
printf("Infos de la personne : nom,prenom !");
scanf(" %s %s",e.nom,e.prenom);
printf("\n adresse (no de rue,rue,ville,code postal) ?");
scanf("\n %d %s %s %s",&e.adre.no,e.adre.rue,e.adre.ville,e.adre.cp);
fwrite(&e,sizeof(personne),1,x);
printf("\n encore ?o/n");
rep=getche();
}while (rep=='o'); /* tant que la reponse est o on execute le do */
fclose(x);
break;
/*******************************************************************************/
case 2:
clrscr();
x=fopen("Agenda.txt","r"); /* ouverture du fichier en mode lecture */
fread(&e,sizeof(personne),1,x);
while (!feof(x)) /* tant que non fin de fichier */
{
printf("\n %s %s",e.nom,e.prenom);
printf("\n %d %s %s %s",e.adre.no,e.adre.cp,e.adre.rue,e.adre.ville);
fread(&e,sizeof(personne),1,x);
}
fclose(x);
getch();
break;
/*******************************************************************************/
case 3:
printf("\n Quel est le nom et le prenom de la personne ?");
scanf("%s %s",nom,prenom);
x=fopen("Agenda.txt","r+"); /* source */
y=fopen("Agenda.txt","r+"); /* cible */
fread(&e,sizeof(personne),1,x);
while (!feof(x)) /* tant que non fin de fichier */
{
if (strcmp(nom,e.nom)==0 && (prenom,e.prenom)==0)
{
printf("\n nouvelle adresse !?");
scanf("%d %s %s %s",&e.adre.no,e.adre.cp,e.adre.rue,e.adre.ville);
}
fwrite(&e,sizeof(personne),1,y);
fread(&e,sizeof(personne),1,x);
}
fclose(x);
fclose(y);
}
}while(choix!=4);
}
/*******************************************************************************/
int menu() /* definition de fontion */
{
int choix;
clrscr();
printf("\n 1.Création \n 2.Consultation \n 3.Modification 4.Quitter \n");
scanf("%d",&choix);
return choix;
}
/********************************************************************************/
/* FIn du code */