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
|
#include<stdio.h>
#include<stdlib.h>
int main (int argc, char const* argv[])
{
FILE *fp;
char nom[20], ch;
char prenom[20];
char filename[20];
int age;
puts ("Introduisez un nom de fichier");
gets(filename);
if ((fp = fopen(filename,"a")) == NULL)
{
fprintf(stderr,"Erreur à l'ouverture du fichier %s", filename);
exit(1);
}
while(1)
{
puts("Entrez votre nom : ");
scanf("%s", &nom);
puts("Entrez votre prenom : ");
scanf("%s", &prenom);
puts("Entrez votre age : ");
scanf("%d", &age);
printf("Vous avez entre\n\nNom : %s \nPrenon : %s \nAge : %d\n", nom, prenom, age);
if (age < 18)
{
printf("Attention :Le sujet est mineur\n");
}
else
{
printf("OK le sujet est majeur\n");
}
fprintf(fp,"Nom = %s - Prenom = %s - Age = %d\n", nom, prenom, age);
puts("\nAutre contact [o]ui ou [n]on ?");
do
{
ch = getchar();
} while (ch != 'n' && ch != 'o');
if (ch =='n')
/*fclose(fp);*/
break;
}
printf("\n");
fclose(fp);
return 0;
} |
Partager