#include /* Pour l'utilisation de printf */ #include /* Pour l'utilisation de strcpy */ /* ==================================================================== */ struct personne /* Definition d'un nouveau type : struct personne */ { char nom[256]; char prenom[256]; int age; }; struct personne createPersonne(char nom[], char prenom[], int age) { struct personne p; strcpy(p.nom,nom); /* p.nom <= nom */ strcpy(p.prenom,prenom); /* p.prenom <= prenom */ p.age = age; /* p.age <= age */ return p; } void printPersonne(struct personne p) { printf("nom: %s\n",p.nom); printf("prenom: %s\n",p.prenom); printf("age: %d ans\n",p.age); } void anniversaire(struct personne* p) { (*p).age = (*p).age + 1; printf("Bon anniversaire %s !\n",(*p).prenom); } /* ==================================================================== */ struct ePersonne /* definition d'un nouveau type : struct ePersonne */ { struct personne p; char email[256]; }; struct ePersonne createEPersonne(char nom[], char prenom[], int age, char email[]) { struct ePersonne ep; #if 1 strcpy(ep.p.nom,nom); /* 1) ep.p.nom <= nom */ strcpy(ep.p.prenom,prenom); /* 2) ep.p.prenom <= prenom */ ep.p.age = age; /* 3) ep.p.age <= age */ strcpy(ep.email,email); /* 4) ep.mail <= mail */ #else ep.p = createPersonne(nom,prenom,age); /* 1) + 2) + 3) */ strcpy(ep.email,email); /* ep.mail <= mail */ #endif return ep; } void printEPersonne(struct ePersonne ep) { #if 1 printf("nom: %s\n",ep.p.nom); /* 1) */ printf("prenom: %s\n",ep.p.prenom); /* 2) */ printf("age: %d ans\n",ep.p.age); /* 3) */ printf("email: %s\n",ep.email); /* 4) */ #else printPersonne(ep.p); /* 1) + 2) + 3) */ printf("email: %s\n",ep.email); #endif } /* ==================================================================== */ int main(void) { struct ePersonne ePers1={{"Leblanc", "Maurice", 77},"leblanc@univ-brest.fr"}; struct ePersonne ePers2; ePers2=createEPersonne("Christie","Agatha",86,"christie@univ-brest.fr"); printf("ePersonne 1:\n"); printEPersonne(ePers1); printf("ePersonne 2:\n"); printEPersonne(ePers2); anniversaire(&(ePers1.p)); return 0; }