principal

Dependencies:   mbed fastlib vga640x400

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fonctionFichier.cpp Source File

fonctionFichier.cpp

00001 #include "mbed.h"
00002 #include "fichier.h"
00003 
00004 
00005 
00006     /*-------------------------------------------*/ 
00007     /* COMPTE LE NOMBRE DE LIGNE DANS LE FICHIER */
00008     /*-------------------------------------------*/ 
00009 int nombre_ligne_fichier(FILE* fp){
00010     int total = 0;
00011     char ligne[500];  
00012     rewind(fp);
00013     
00014     while ( fgets(ligne, 500, fp) != NULL){
00015         total++;;
00016     }
00017     rewind(fp);
00018     return total;
00019 }
00020 
00021     /*-----------------------------------*/ 
00022     /* RETOURNE LE CONTENU DE LA LIGNE X */
00023     /*-----------------------------------*/ 
00024  void retourne_ligne(int num, char ligne[500], FILE* fp){
00025     int cmpt = 1;
00026     rewind(fp); 
00027     
00028     fgets(ligne, 500, fp);
00029     
00030     while( cmpt != num){
00031         fgets(ligne, 500, fp);
00032         cmpt++;
00033     }
00034     
00035     rewind(fp);
00036     return;
00037      
00038 }
00039 
00040 char* retourne_element_ligne(int num, char ligne[500]){
00041     int cmpt = 1;
00042     char *element;
00043     char stock[500];
00044     
00045     strcpy(stock, ligne);
00046     element = strtok(stock, ";");
00047     //printf ("stock : %s\n\r", element);
00048     while( cmpt != num){
00049         element = strtok( NULL, ";");
00050         cmpt++;
00051         //printf ("stock : %s\n\r", element);
00052         element = element;
00053     }
00054     return element;    
00055 }
00056     
00057 int num_bonne_reponse( char ligne[500]){
00058     char* element;
00059     int reponse;
00060     element = retourne_element_ligne(6, ligne); 
00061     reponse = atoi( element ); 
00062     return reponse;
00063     }