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 73 74 75 76 77 78
|
#include<stdio.h>
#include<conio.h>
typedef struct individu1{
char nom[30];
int an_nais;
char tel[20];
}individu;
void saisir2(individu*ptidv)
{
printf("entrer un nom:\n");
scanf("%s",ptidv->nom);
printf("entrer l'annee de naissance:\n");
scanf("%d",&ptidv->an_nais);
printf("entrer le numero telephone:\n");
scanf("%s",ptidv->tel);
}
int identiques(individu m1,individu m2)
{
int test=0;
if((m1.nom == m2.nom) && (m1.an_nais == m2.an_nais) && (m1.tel == m2.tel))
test=1;
return test;
}
void afficher(individu t[],int nbInd)
{
int i;
for(i=0;i<nbInd;i++)
{
printf("%s\n",t[i].nom);
printf("%d\n",t[i].an_nais);
printf("%s\n",t[i].tel);
}
}
int position(individu m,individu t[],int nbInd)
{
int pos=-1,i=0;
while(pos==-1 && i<nbInd)
{if(identiques(m,t[i])==1)
pos=i;
i++;
}
return pos;
}
int chercher(individu m,individu t[],int nbInd,char*nt)
{
int pos=position(m,t,nbInd);
if(pos!=-1)
{nt=t[pos].tel;
return 1;
}
else
return 0;
}
main()
{
int nbr,pos,i;individu m;char *ch;
printf("entrer le nombre des individus:\n");
scanf("%d",&nbr);
individu tab[nbr];
printf("lecture du tebleau:\n\n");
for(i=0;i<nbr;i++)
{
saisir2(&m);
tab[i]=m;
}
printf("affichage des infos concernent les individus du tableau:\n");
afficher(tab,nbr);
printf("entrer un individu pour le chercher:\n");
saisir2(&m);
pos=chercher(m,tab,nbr,ch);
printf("%d",pos);
if(pos==0)
printf("element inexistant:\n");
else
printf("sa position est:%d \n son numero telephone est:%s",pos,ch);
getch();
} |
Partager