#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); } int testPersonne(struct personne p1, struct personne p2) { int test = 1; /* vrai */ if (strcmp(p1.nom,p2.nom)!=0) { test = 0; /* faux */} else if (strcmp(p1.prenom,p2.prenom)!=0) { test = 0; /* faux */} else if (p1.age!=p2.age) { test = 0; /* faux */} return test; } /* ==================================================================== */ int main(void) { struct personne pers1={"Leblanc", "Maurice", 77}; struct personne pers2; #if 0 pers2 = {"Leblanc", "Maurice", 77}; /* INTERDIT !!! */ /* {.., .., ..} uniquement a la creation */ #endif pers2 = pers1; /* Affectation directe ok */ /* Rappel : */ if (testPersonne(pers1,pers2)==1) /* if (pers1==pers2) est INTERDIT !! */ { printf("C'est la meme personne !\n"); } return 0; }