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
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "repertoire.h"
#include "lireClavier.h"
#include "repertoireFichier.h"
int menu(){
int option=0;
printf("1: ajouter un contact\n");
printf("2: rechercher un contact\n");
printf("3: supprimer un contact\n");
printf("4: afficher tous les contacts\n");
printf("5: quitter\n");
while(option<1 || option>5){
printf(" votre choix: ");
option = lireEntier();
}
return option;
}
char* saisir_string(char* chose, char* op, char *res, int taille){
printf("Entrez le %s du contact Ã* %s\n",chose,op);
lireMot(res, taille);
return res;
}
int main(){
Repertoire lerep;
int i;
int option=0;
char nom[99+1];
char numero[19+1];
Contact cont;
bool done;
nom[0] = numero[0] = '\0';
for(i=0; i<100; i++){ //nettoyage du répertoire?
strcpy(lerep[i].nom,"");
strcpy(lerep[i].numero,"");
}
restCont(lerep); //copie la liste de contact du fichier "repertoire.txt" dans le tableau "lerep" de structure "Contact".
while(option != 5){
option = menu();
switch(option){
case 1:
saisir_string("nom","ajouter", nom, 99);
saisir_string("numero","ajouter", numero, 19);
ajouterContact(nom,numero,lerep);
break;
case 2:
saisir_string("morceau du nom","rechercher", nom, 99);
cont = rechercherContact(nom,lerep);
if (strlen(cont.nom)>0){
printf("nom: %s numéro: %s\n",cont.nom,cont.numero);
}else{
printf("aucun contact trouvé\n");
}
break;
case 3:
saisir_string("morceau du nom","supprimer", nom, 99);
done = supprimerContact(nom,lerep);
if (done)
printf("contact supprimé\n");
else
printf("aucun contact correspondant: %s\n",nom);
break;
case 4:
afficherRepertoire(lerep);
break;
case 5:
printf("au revoir\n");
saveCont(lerep); //copie de la liste des contactes du tableau "lerep" dans le fichier "repertoire.txt".
}
}
return 0;
} |
Partager