diff --git a/Tp7_Struct/Tp7.c b/Tp7_Struct/Tp7.c index 1a536e7..a5b3f89 100644 --- a/Tp7_Struct/Tp7.c +++ b/Tp7_Struct/Tp7.c @@ -1,5 +1,6 @@ #include #include +#include #define ContigueLength 512 #define NbChar 32 @@ -123,6 +124,23 @@ void deletePers(char nomPers[], Annuaire* annuaire){ } } +void ajoutPers(Personne p, Annuaire* annuaire){ + int i=annuaire->dernier; + annuaire->dernier+=1; + int trouve = 0; + while(i>=0 && trouve ==0){ + if((strcmp(p.nom, annuaire->listePers[i].nom)<0)){ + annuaire->listePers[i+1]=annuaire->listePers[i]; + } else if((strcmp(p.nom, annuaire->listePers[i].nom)>=0)){ + trouve =1; + annuaire->listePers[i+1]=p; + } + i--; + } +} + + + int main(int argc, char *argv[]){ @@ -152,6 +170,17 @@ int main(int argc, char *argv[]){ printf("Le nouveau numero de %s sera: %s\n",argv[2], argv[3]); } else if ( argc == 3 && strcmp(argv[1],"supprimer")==0 ){ deletePers(argv[2],&annuaire); + } else if ( argc != 7 && strcmp(argv[1],"ajouter")==0 ){ + ///annuaire ajouter Dupont 01 01 2011 0328753542 + + Personne p; + strcpy(p.nom,argv[2]); + strcpy(p.prenom,argv[3]); + p.date.jour=atoi(argv[4]); + p.date.mois=atoi(argv[5]); + p.date.annee=atoi(argv[6]); + strcpy(p.tel,argv[7]); + ajoutPers(p,&annuaire); } afficheAnnuaire(annuaire); diff --git a/Tp7_Struct/Tp7.o b/Tp7_Struct/Tp7.o index 9408618..2909453 100644 Binary files a/Tp7_Struct/Tp7.o and b/Tp7_Struct/Tp7.o differ diff --git a/Tp7_Struct/prog b/Tp7_Struct/prog index e63021e..78e346c 100755 Binary files a/Tp7_Struct/prog and b/Tp7_Struct/prog differ -- libgit2 0.21.2