Please, some one can explain for me why this program does not work ?
I'm trying to read and write from the file by using r+
. The file test.txt
exists and the writing is executed correctly. However, the reading does not work.
int main() {
FILE* fichier = NULL;
int age, TAILLE_MAX=10;
char chaine[TAILLE_MAX];
fichier = fopen("test.txt", "r+");
if (fichier != NULL)
{
printf("give your age ? ");
scanf("%d", &age);
fprintf(fichier, "Hello you have %d year old", age);
while (fgets(chaine, TAILLE_MAX, fichier) != NULL)
{
printf("%s", chaine); //does not print
}fclose(fichier);
}
return 0;
}
By does not work I mean it does not display any thing ! Even if the file contains some the sentence you have ... year old. There is no Error. Just the program does not print the content of the file