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
| #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{ char buffer[256] ;
float x, y, z, temps, att ;
FILE *Hfile ;
if((Hfile=fopen("file.txt", "r+"))==NULL)
{
fprintf(stderr, "Erreur d'ouverture du fichier file.txt\n") ;
return EXIT_FAILURE ;
}
printf("X\tY\tZ\tTEMPS\tATT\n") ;
while(!feof(Hfile))
{
if((fscanf(Hfile, "point (%f,%f,%f)\n", &x, &y, &z))==3)
{
printf("%2.3f\t%2.3f\t%2.3f", x, y, z) ;
}
else if((fscanf(Hfile, "temps=%f\n", &temps))==1)
{
printf("\t%2.3f", temps) ;
}
else if((fscanf(Hfile, "att=%f\n", &att))==1)
{
printf("\t%2.3f\n", att) ;
}
else fgets(buffer, 128, Hfile) ; /* Lecture ligne autre */
}
fclose(Hfile) ;
return EXIT_SUCCESS ;
} |
Partager