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
|
#include <stdio.h>
#include <string.h>
#include <conio2.h>
struct date
{
int jour;
int mois;
int annee;
};
typedef struct
{
char nom[32];
char prenom[32];
struct date date_naissance;
}
fiche_s;
int fclean (char *s, FILE * fp)
{
int err;
char *p = strchr (s, '\n');
if (p != NULL)
{
*p = 0;
err = 0;
}
else
{
int c;
while ((c = fgetc (fp)) != '\n' && c != EOF)
{
}
err = 1;
}
return err;
}
void saisie_date (struct date *p_date)
{
int n;
do
{
char line[sizeof "jj mm aaaa\n"];
printf ("Entrez la date de naissance jj mm aaaa : ");
fflush (stdout);
fgets (line, sizeof line, stdin);
fclean (line, stdin);
/* analyse des 3 valeurs saisies. Conversion en int
retourne le nombre de conversions reussies.
*/
n = sscanf (line, "%d %d %d",
&p_date->jour, &p_date->mois, &p_date->annee);
}
while (n != 3);
}
void SaisieFiche (fiche_s * p_fiche)
{
clrscr ();
printf ("Entrez le nom : ");
fflush (stdout);
fgets (p_fiche->nom, sizeof p_fiche->nom, stdin);
fclean (p_fiche->nom, stdin);
printf ("Entrez le prenom : ");
fflush (stdout);
fgets (p_fiche->prenom, sizeof p_fiche->prenom, stdin);
fclean (p_fiche->prenom, stdin);
saisie_date (&p_fiche->date_naissance);
}
int main (void)
{
fiche_s fiche;
SaisieFiche (&fiche);
printf ("%s %s\n", fiche.nom, fiche.prenom);
printf ("Ne le : %02d/%02d/%04d\n",
fiche.date_naissance.jour, fiche.date_naissance.mois,
fiche.date_naissance.annee);
return 0;
} |
Partager