Exemple d’utiliation de la fonction ‘int fflush ( FILE *fichier)’ pour vider le tampon

Author:


Download


//Bibiothèque:       #include 
//Syntaxe:           int fflush(FILE *fichier);
//Retour:            0 en cas de succès ou EOF en cas d'erreur. 

  #include 
  #include 

typedef struct {
  char nom[64];
} item;

  int main(void){
     FILE *fichier;

item itemcache[32];
     if((fichier=fopen("test.txt", "rb"))==NULL) {
        printf("Impossible d'ouvrir le fichier.");
        exit(1);
     }

	 char ch = 'C';
      int i;
      for(i=0; i<5; i++)
	  {
        fwrite(itemcache, sizeof(item), 1, fichier);
        fflush(fichier);
      }
      fclose(fichier);
      return 0;
  }

Leave a Reply

Your email address will not be published. Required fields are marked *