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
| #include <stdio.h>
#include <stdlib.h>
typedef struct {
char* nom;
unsigned int age;
char* adresse;
/*Personne[][] amis;*/
}Personne;
/*Prototypes*/
/*Au début une personne n'a pas d'amis, son nom ne change pas mais son adresse peut*/
void naissance(Personne* quidam,char* nom, unsigned int age, char* adresse);
/*Crée un lien d'amitié symétrique */
void sont_amis(Personne a,Personne b);
int affinites(Personne a,Personne b);
void demenage(Personne a, char* adresse);
void affiche(Personne* a);
int main(void){
/*
Nelly Bord (NB) et ALbert Zweinstein (AZ) sont amis
Ahmas Pamouzh (AP) et Pierre Kiroul sont amis
Claude During (CD), Georges Chatnonne (GC) et Alan Boule (AB) sont tous 3 amis
NB, AP, GC et CD sont amis
Affichez le nombre d'amis communs à AB et AP puis le nombre d'amis communs à GC et CD
Faire déménager NB et l'afficher.
*/
Personne* NB;
naissance(*NB,"Bord Nelly", 28, "Rue du Petit-chêne");
affiche(NB);
return 0;
}
/* ================================================================== */
void naissance(Personne* quidam,char* nom,unsigned int age, char* adresse){
*quidam=malloc(sizeof(Personne));
quidam->nom = calloc(strlen(nom)+1,sizeof(char));
if(quidam->nom !=NULL){
strcopy(quidam->nom, nom);
}
quidam->adresse = calloc((strlen(adresse)+1,sizeof(char));
if(quidam->adresse != NULL){
strcopy(quidam->adresse, adresse);
}
quidam->age = malloc(3*sizeof(unsigned int));
if(quidam->age != NULL){
quidam->age = age;
}
}
/* ================================================================== */
void sont_amis(Personne a,Personne b){
/*a.amis
b.amis*/
}
/* ================================================================== */
void affiche(Personne* a){
printf("nom : %s\n ",a->nom);
printf("age : %d\n",a->age);
printf("adresse : %s\n",a->adresse);
} |
Partager