principal

Dependencies:   mbed fastlib vga640x400

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers exmain.cpp Source File

exmain.cpp

00001 #include "mbed.h"
00002 #include "fichier.h"
00003   
00004  
00005 LocalFileSystem local("local");             // Create the local filesystem under the name "local"
00006  
00007 int exmain() {
00008     int i,j,nb;
00009     /*
00010     FILE *fp = fopen("/local/out.txt", "w");  // Open "out.txt" on the local file system for writing
00011     fprintf(fp, "coucou clement World!");
00012     fclose(fp);
00013     //remove("/local/out.txt");                 // Removes the file "out.txt" from the local file system
00014     */
00015     
00016     DIR *d = opendir("/local");               // Opens the root directory of the local file system
00017     struct dirent *p;
00018     while((p = readdir(d)) != NULL) {         // Print the names of the files in the local file system
00019       printf("%s\n\r", p->d_name);              // to stdout.
00020     }
00021     closedir(d);
00022 
00023 
00024     FILE *fp = fopen("/local/form.csv", "r"); 
00025     if(!fp) { 
00026         error("Could not open file!\n\r");
00027     }
00028     
00029     
00030     char ligne[500];
00031     char* morceau;
00032     /*-------------------------------------------*/ 
00033     /* COMPTE LE NOMBRE DE LIGNE DANS LE FICHIER */
00034     /*-------------------------------------------*/ 
00035     printf("nombre de ligne %d\n\r", nb = nombre_ligne_fichier(fp));
00036     
00037     for( i = 2; i <= nb; i++){     
00038         /*-----------------------------------*/ 
00039         /* RETOURNE LE CONTENU DE LA LIGNE X */
00040         /*-----------------------------------*/ 
00041         retourne_ligne(i,ligne,fp);
00042         printf("ligne %d est %s\n\r",i,ligne);
00043     
00044         /*-----------------------------------*/ 
00045         /* RETOURNE L'ÉLÉMENT X DE LA LIGNE  */
00046         /*-----------------------------------*/ 
00047         morceau = retourne_element_ligne(1, ligne);
00048         printf("la question est: %s \n\r", morceau);
00049         
00050         /*-----------------------------------*/ 
00051         /* RETOURNE L'ÉLÉMENT X DE LA LIGNE  */
00052         /*-----------------------------------*/ 
00053         for(j = 1; j < 5; j++){
00054             morceau = retourne_element_ligne(j+1, ligne);
00055             printf("Reponse %d: %s \n\r",j, morceau);
00056         }
00057     
00058         /*----------------------------------------*/ 
00059         /* RETOURNE LA BONNE REPONSE DE LA LIGNE  */
00060         /*----------------------------------------*/     
00061         j = num_bonne_reponse(ligne);
00062         morceau = retourne_element_ligne(j+1, ligne);
00063         printf("bonne reponse est la %d: %s \n\r",j, morceau);
00064     
00065         /*-----------------------------------*/ 
00066         /* RETOURNE L'ÉLÉMENT X DE LA LIGNE  */
00067         /*-----------------------------------*/ 
00068         morceau = retourne_element_ligne(7, ligne);
00069         printf("la raison: %s \n\r", morceau);
00070     }
00071     fclose(fp);
00072     
00073 }