Commit b8af5d9545e4088b344104d4d2a5e37656ac39fc
1 parent
c12646b9
Le C c de l'o
Showing
3 changed files
with
29 additions
and
0 deletions
Show diff stats
Tp7_Struct/Tp7.c
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <string.h> | 2 | #include <string.h> |
3 | +#include <stdlib.h> | ||
3 | 4 | ||
4 | #define ContigueLength 512 | 5 | #define ContigueLength 512 |
5 | #define NbChar 32 | 6 | #define NbChar 32 |
@@ -123,6 +124,23 @@ void deletePers(char nomPers[], Annuaire* annuaire){ | @@ -123,6 +124,23 @@ void deletePers(char nomPers[], Annuaire* annuaire){ | ||
123 | } | 124 | } |
124 | } | 125 | } |
125 | 126 | ||
127 | +void ajoutPers(Personne p, Annuaire* annuaire){ | ||
128 | + int i=annuaire->dernier; | ||
129 | + annuaire->dernier+=1; | ||
130 | + int trouve = 0; | ||
131 | + while(i>=0 && trouve ==0){ | ||
132 | + if((strcmp(p.nom, annuaire->listePers[i].nom)<0)){ | ||
133 | + annuaire->listePers[i+1]=annuaire->listePers[i]; | ||
134 | + } else if((strcmp(p.nom, annuaire->listePers[i].nom)>=0)){ | ||
135 | + trouve =1; | ||
136 | + annuaire->listePers[i+1]=p; | ||
137 | + } | ||
138 | + i--; | ||
139 | + } | ||
140 | +} | ||
141 | + | ||
142 | + | ||
143 | + | ||
126 | 144 | ||
127 | 145 | ||
128 | int main(int argc, char *argv[]){ | 146 | int main(int argc, char *argv[]){ |
@@ -152,6 +170,17 @@ int main(int argc, char *argv[]){ | @@ -152,6 +170,17 @@ int main(int argc, char *argv[]){ | ||
152 | printf("Le nouveau numero de %s sera: %s\n",argv[2], argv[3]); | 170 | printf("Le nouveau numero de %s sera: %s\n",argv[2], argv[3]); |
153 | } else if ( argc == 3 && strcmp(argv[1],"supprimer")==0 ){ | 171 | } else if ( argc == 3 && strcmp(argv[1],"supprimer")==0 ){ |
154 | deletePers(argv[2],&annuaire); | 172 | deletePers(argv[2],&annuaire); |
173 | + } else if ( argc != 7 && strcmp(argv[1],"ajouter")==0 ){ | ||
174 | + ///annuaire ajouter Dupont 01 01 2011 0328753542 | ||
175 | + | ||
176 | + Personne p; | ||
177 | + strcpy(p.nom,argv[2]); | ||
178 | + strcpy(p.prenom,argv[3]); | ||
179 | + p.date.jour=atoi(argv[4]); | ||
180 | + p.date.mois=atoi(argv[5]); | ||
181 | + p.date.annee=atoi(argv[6]); | ||
182 | + strcpy(p.tel,argv[7]); | ||
183 | + ajoutPers(p,&annuaire); | ||
155 | } | 184 | } |
156 | 185 | ||
157 | afficheAnnuaire(annuaire); | 186 | afficheAnnuaire(annuaire); |
Tp7_Struct/Tp7.o
No preview for this file type
Tp7_Struct/prog
No preview for this file type