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
| #include<conio.h>
#include<stdio.h>
FILE *f;
struct nom
{ char nom,prenom;
int cin;
};
main()
{ int i,drp=0,choix;
struct nom t[100],aux;
do
{
printf("1\n");
printf("2");
scanf("%d",&choix);
}
while((choix<1)||(choix>2));
switch(choix)
{
case 1 : {
f=fopen("c:\\ex$.txt","w+");
if(f==NULL)
printf("erreur");
else
{printf("donner le nom");
scanf("%s",t[i].nom);
fprintf(f,"%s\t\t",t[i].nom);
printf("donner le prenom");
scanf("%s",t[i].prenom);
fprintf(f,"%s\t\t",t[i].prenom);
printf("donner le cin");
scanf("%d",t[i].cin);
fprintf(f,"%d\n",t[i].cin);
}
fclose(f);
break;
}
case 2 :{
f=fopen("c:\\ex$.txt","w+");
if(f==NULL)
printf("erreur");
else
{fscanf(f,"%s",t[i].nom);
fscanf(f,"%s",t[i].prenom);
fscanf(f,"%d",t[i].cin);
do
{
for(i=0;i<100;i++)
if(t[i].cin < t[i+1].cin)
drp=1;
aux=t[i];
t[i]=t[i+1];
t[i+1]=aux;
}
while(drp==1);
printf("%s\t\t%s\t\t%d",t[i].nom,t[i].prenom,t[i].cin);
}
fclose(f);
break;
}
}
getch();
} |
Partager