Ecriture dans un fichier txt en C
Résolu
amine_marc
Messages postés
286
Statut
Membre
-
amine_marc Messages postés 286 Statut Membre -
amine_marc Messages postés 286 Statut Membre -
Bonjour,
J'ai un pb dans une fonction, pour écrire dans un fichier .txt en C, qui ne se compile pas dans mon programme...... voilà le code:
//--------------------------------------------------------------------------------------------------
void creer_fichier(void){
char choix_nv;
FILE *fp;
Etudiant Etud;
printf("---- CREATION DU FICHIER ---- \n");
fp = fopen("registre_etd_mod.txt","w");
do{
printf("Nouveau Etudiant (o/n)..............? ");
//choix_nv =(char)getchar();
scanf("%s",&choix_nv);
if ((choix_nv=='o')||(choix_nv=='O'))
{
printf("Code Etudiant : ");
scanf("%s",Etud.Code_etd);
printf("Nom Etudiant : ");
scanf("%s",Etud.Nom_etd);
printf("Prenom Etudiant : ");
scanf("%s",Etud.Prenom_etd);
//fwrite(&Etud,sizeof(Etudiant),1,fp);
fprintf(fp,"\n %s %s %s", Etud.Code_etd, Etud.Nom_etd, Etud.Prenom_etd);
else
{
printf("\nMerci pour votre visite! \n");
getch(); exit(1);
}
}while((choix_nv=='o')||(choix_nv=='O'));
fclose(fp);
}
//-------------------------------------------------------------------------------
veuillez me dire comment résoudre ce pb, et merci d'avance.
J'ai un pb dans une fonction, pour écrire dans un fichier .txt en C, qui ne se compile pas dans mon programme...... voilà le code:
//--------------------------------------------------------------------------------------------------
void creer_fichier(void){
char choix_nv;
FILE *fp;
Etudiant Etud;
printf("---- CREATION DU FICHIER ---- \n");
fp = fopen("registre_etd_mod.txt","w");
do{
printf("Nouveau Etudiant (o/n)..............? ");
//choix_nv =(char)getchar();
scanf("%s",&choix_nv);
if ((choix_nv=='o')||(choix_nv=='O'))
{
printf("Code Etudiant : ");
scanf("%s",Etud.Code_etd);
printf("Nom Etudiant : ");
scanf("%s",Etud.Nom_etd);
printf("Prenom Etudiant : ");
scanf("%s",Etud.Prenom_etd);
//fwrite(&Etud,sizeof(Etudiant),1,fp);
fprintf(fp,"\n %s %s %s", Etud.Code_etd, Etud.Nom_etd, Etud.Prenom_etd);
else
{
printf("\nMerci pour votre visite! \n");
getch(); exit(1);
}
}while((choix_nv=='o')||(choix_nv=='O'));
fclose(fp);
}
//-------------------------------------------------------------------------------
veuillez me dire comment résoudre ce pb, et merci d'avance.
A voir également:
- Ecriture dans un fichier txt en C
- Fichier bin - Guide
- Comment réduire la taille d'un fichier - Guide
- Comment ouvrir un fichier epub ? - Guide
- Fichier rar - Guide
- Fichier .dat - Guide