You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
1.7 KiB

#include <stdio.h>
#include <string.h>
#include "sae.h"
int creeadherent(int *tNC,char *tN,char *tPR,int *tA,int *tCA,int *tPO, int Tmax)
{
int NC,N,PR,A,CA,PO, i=0;
FILE *fe;
fe=fopen("adherent.txt","r");
if(fe == NULL)
{
printf("pbouvrfichier\n");
return -1;
}
fscanf(fe,"%d %s %s %d %d %d",&NC,&N,&PR,&A,&CA,&PO);
while (!feof(fe))
{
if(i==Tmax)
{
printf("%d \t %d\n",i, Tmax);
printf("capasité atteinte\n");
fclose(fe);
return -1;
}
tNC[i]=NC;
tN[i]=N;
tPR[i]=PR;
tA[i]=A;
tCA[i]=CA;
tPO[i]=PO;
i++;
fscanf(fe,"%d %s %s %d %d %d",&NC,&N,&PR,&A,&CA,&PO);
}
fclose(fe);
return i;
}
void affichageA(int *tNC,char *tN,char *tPR,int *tA,int *tCA,int *tPO, int n)
{
int i;
printf("----------------------------------------------------------------------------\n");
printf("n°client nom\t prenom\t age\t carte\t point\n");
for (i=0;i<n;i++)
{
printf("%d\t %c\t %c\t %d\t %d\t %d\n",tNC[i],tN[i],tPR[i],tA[i],tCA[i],tPO[i]);
}
printf("----------------------------------------------------------------------------\n");
}
int recherche(int*tNC,int n, int val, int* trouve)
{
int i;
for(i=0;i<n;i++)
{
if (tNC[i]==val)
{
printf("le valeur %d est trouvé, sa position est %d\n",val,i);
*trouve=1;
return i;
}
if(val<tNC[i])
{
printf("le valeur %d n'est pas trouvé, son position d'insertion est %d\n",val,i);
*trouve=0;
return i;
}
}
printf("le valeur %d n'est pas trouvé, sa position d'insertion est %d\n",val,i);
*trouve=0;
return i;
}
void globale()
{
int n,valtrouve,trouve,tmax=50;
int tNC[50],tA[50],tCA[50],tPO[50];
char tN[50],tPR[50];
n=creeadherent(tNC,tN,tPR,tA,tCA,tPO,250);
affichageA(tNC,tN,tPR,tA,tCA,tPO, n);
valtrouve=recherche(tNC,n,100,&trouve);
}