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
   | #include <stdio.h>
#include <stdlib.h>
#define fich "H:\\testStage\\exoc.txt";//chemin et nom et du fichier texte à traiter
void main()
 {
    FILE *f_read;
     int c,i = 0,j = 0,k;
     char tab[256];
 
    f_read = fopen("H:\\testStage\\exoc.txt", "r");
     if (!f_read) // test ouverture du fichier 
    {
         printf("Impossible d'ouvrir le fichier\n");
         exit(-1);
     }
 
    /*cette partie affiche aussi le contenu du fichier
    mais ne nous est pas très utile car on veut controler l'affichage*/
    /*while (!feof(f_read))
    putchar(fgetc(f_read));
    printf("\nVOILA LE CONTENU DU FICHIER LU AU DESSUS \n");
    i=0;*/
    // seconde manipulation d'affichage
    while (!feof(f_read))
     {
         c = fgetc(f_read); //ramene un int dans c
        c =(char)c; // cast du int en char afin d'afficher les caractères
        //printf("%c",c); // affiche le contenu du fichier
        tab[i] = c;
         i++; 
     }
 
    /*while (j<i)
    { //tab[j]= (char) tab[j];
        //printf("%c",tab[j]);//affiche aussi le contenu du fichier
        if (tab[j]='#')
            printf("%c",tab[j+1]);
        j++;
    }*/
    /*while ((tab[j]!='\\')||(tab[j]=='>'))
    {
        branch[j]= cpt;
        cpt++;
        j++; 
    }*/
    for(j=0;j<i;j++)
     { 
         if (tab[j]=='#')
             tab[j]='\b'; 
         if (tab[j]=='>')
             tab[j]='\r';
         printf("%c",tab[j]);
     } 
     fclose(f_read); // fermeture du fichier traité
} | 
Partager