Lecture fichier mais rien ne s'affiche
Code:
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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 10
typedef char Chaine[N];
typedef struct Client Client;
struct Client
{
int id;
Chaine nom;
};
void ajouteClientFichier()
{
FILE * fichier = NULL;
Client c1;
fichier = fopen("dataClients.txt", "a");
if (fichier != NULL)
{
// Saisie utilisateur
printf("Entrer l'identifiant du client : ");
scanf("%d", &c1.id);
printf("Entrer le nom du client : ");
scanf("%s", &c1.nom);
// Ecriture dans le fichier
fprintf(fichier, "\n%d %s", c1.id, c1.nom);
}
else
{
printf("Impossible d'ouvrir le fichier dataClients.txt");
}
fclose(fichier);
}
void afficheClientsFichier(Chaine nom)
{
FILE* fichier = NULL;
char ligne[100] = "";
Client c1;
fichier = fopen("dataClients.txt", "r");
if (fichier != NULL)
{
while (fgets(ligne, 100, fichier) != NULL) // On lit le fichier tant qu'on ne reçoit pas d'erreur (NULL)
{
if(strcmp(nom, c1.nom) == 0)
{
printf("%s", ligne); // On affiche la chaîne qu'on vient de lire
}
}
fclose(fichier);
}
}
int main()
{
//ajouteClientFichier();
afficheClientsFichier("Corentin");
return 0;
} |
Voici mon code mais lorsque je compile rien ne s'affiche, sachant que j'ai 5 clients enregistrés dont Corentin qui est en paramètre dans ma fonction