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 79 80 81 82 83 84 85 86 87 88
| #include<stdio.h>
#include <string.h>
#include <stdlib.h>
struct _date
{
int jour;
int mois;
int annee;
};
typedef struct cm
{
char nom[20];
char prenom[20];
struct _date date;
}cmp;
typedef struct p
{
cmp compte;
struct p *next;
}liste_compte;
cmp saisircmp()
{
cmp c;
printf("saisissez votre nom : ");scanf("%s",&c.nom);
printf("aisissez votre prenom : ");scanf("%s",&c.prenom);
printf("aisissez la date ");
printf("\t aisissez le jour : ");scanf("%d",&c.date.jour);
printf("\t aisissez le mois : ");scanf("%d",&c.date.mois);
printf("\t aisissez le annee : ");scanf("%d",&c.date.annee);
return c;
}
void enregistre(cmp *c)
{
FILE *fichier =NULL;
fichier = fopen("daba.txt","a");
fprintf(fichier,"\t\t\tinformation sur le compte\n ");
fprintf(fichier,"prenom : %s \n nom : %s \n",c->prenom,c->nom );
fprintf(fichier," date : %d / %d / %d \n",c->date.jour,c->date.mois,c->date.annee );
fclose(fichier);
}
void ajouterCompte(liste_compte **tete)
{
liste_compte *nv=(liste_compte*)malloc(sizeof(liste_compte));
nv->compte=saisircmp();
enregistre(nv);
nv->next=*tete;
*tete=nv;
}
void afficher(liste_compte **tete)
{
liste_compte *temp=*tete;
while(*temp!=NULL )
{
printf("prenom : %s \n nom : %s \n",*temp->prenom,*temp->nom );
printf(" date : %d / %d / %d \n",*tete->date->jour,*tete->date->mois,*tete->date->annee );
*temp=*temp->next;
}
}
void main(void)
{
liste_compte *tete=NULL;
int i,c;
for(i=1;i<3;i++)
{
printf("\n entrer un nombre ");
scanf("%d",&c);
switch(c)
{
case 1: ajouterCompte(&tete);
break;
case 2:afficher(&tete);
break ;
case 3:
c=0;
break;
}
}
} |