Previous Next Up Index Contents

Exercice 11.14

#include <stdio.h>
main()
{
  /* Noms des fichiers et pointeurs de référence */
  char NOM_FICH[30]; 
  FILE *FICHIER;
  /* Autres variables */
  char C;  /* caractère actuel */
  int NLIGNE, NCOLO; /* position actuelle sur l'écran */
 
  /* Ouverture de l'ancien fichier en lecture */
  do
    {
     printf("Nom du fichier texte : ");
     scanf("%s", NOM_FICH);
     FICHIER = fopen(NOM_FICH, "r"); 
      if (!FICHIER) 
         printf("\aERREUR: Impossible d'ouvrir "
                "le fichier: %s.\n", NOM_FICH);
    }
  while (!FICHIER)  ;
  getchar();
  /* Initialisations des variables */
  NLIGNE  = 0; NCOLO   = 0;
  /* Affichage du fichier */
  while (!feof(FICHIER))
     {
      C=fgetc(FICHIER);
      if (!feof(FICHIER))
         {
          NCOLO++;
          if (NCOLO==80 || C=='\n') /* fin de la ligne */ 
             {
              NLIGNE++;
              if (NLIGNE==25) /* fin de l'écran */ 
                 {
                  getchar();
                  NLIGNE=1;
                 }
              printf("%c",C);
              NCOLO=1;
             }
          else
             printf("%c",C);
         }
     }
   /* Fermeture du fichier */
  fclose(FICHIER);
   return 0;
}


Previous Next Up Index Contents

Feedback - Copyright © 1993,1996,1997 F.Faber