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
| /*Information.c*/
#include<stdio.h>
#include "fpurge.h"
#define MAX 500
void information(void)
{
char nom[MAX];
char prenom[MAX];
char adresse[MAX];
char sexe[MAX];
char option[MAX];
int age;
int telephone;
printf("\n");
printf(" Entrer votre nom : \n");
fgets(nom, MAX, stdin);
fclean(nom, stdin);
printf("Entrer votre prenom: \n");
fgets(prenom, MAX, stdin);
fclean(prenom, stdin);
printf("Entrer votre adresse: \n");
fgets(adresse, MAX, stdin);
fclean(adresse, stdin);
printf("Entrer votre sexe: \n");
fgets(sexe, MAX, stdin);
fclean(sexe, stdin);
printf("Entrer votre option: \n");
fgets(option, MAX, stdin);
fclean(option, stdin);
printf("Entrer votre age: \n");
scanf("%d",&age);
fpurge(stdin);
printf("Entrer votre telephone: \n");
scanf("%d",&telephone);
fpurge(stdin);
//creation d'un pointeur FILE
FILE*pointeurfichier=NULL;
//appel a la fonction fopen
pointeurfichier=fopen("Les informations des etudians.txt","w");
//test sur l'ouverture
if(pointeurfichier!=NULL)
{
fprintf(pointeurfichier,"### les informations ###\n");
fprintf(pointeurfichier," %s \n",nom);
fprintf(pointeurfichier,"%s \n", prenom);
fprintf(pointeurfichier,"%s \n", adresse);
fprintf(pointeurfichier," %s \n", sexe);
fprintf(pointeurfichier,"%s \n", option);
fprintf(pointeurfichier,"%d \n",age);
fprintf(pointeurfichier,"%d \n",telephone);
/*Note: j'ai mis le fclose() dans le printf(),
parce que fclose(NULL) est un comportement indéterminé (qui plante sous Visual),
contrairement à free(NULL) qui est garanti ne rien faire.*/
fclose(pointeurfichier);
}
else
{
printf("impossible d'ouvrir le fichier.\n");
}
} |
Partager