principal

Dependencies:   mbed fastlib vga640x400

Committer:
yokoland95
Date:
Thu Jun 13 15:56:16 2019 +0000
Revision:
2:05fe3543a781
blabla

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yokoland95 2:05fe3543a781 1 #include "mbed.h"
yokoland95 2:05fe3543a781 2 #include "fichier.h"
yokoland95 2:05fe3543a781 3
yokoland95 2:05fe3543a781 4
yokoland95 2:05fe3543a781 5 LocalFileSystem local("local"); // Create the local filesystem under the name "local"
yokoland95 2:05fe3543a781 6
yokoland95 2:05fe3543a781 7 int exmain() {
yokoland95 2:05fe3543a781 8 int i,j,nb;
yokoland95 2:05fe3543a781 9 /*
yokoland95 2:05fe3543a781 10 FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
yokoland95 2:05fe3543a781 11 fprintf(fp, "coucou clement World!");
yokoland95 2:05fe3543a781 12 fclose(fp);
yokoland95 2:05fe3543a781 13 //remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
yokoland95 2:05fe3543a781 14 */
yokoland95 2:05fe3543a781 15
yokoland95 2:05fe3543a781 16 DIR *d = opendir("/local"); // Opens the root directory of the local file system
yokoland95 2:05fe3543a781 17 struct dirent *p;
yokoland95 2:05fe3543a781 18 while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
yokoland95 2:05fe3543a781 19 printf("%s\n\r", p->d_name); // to stdout.
yokoland95 2:05fe3543a781 20 }
yokoland95 2:05fe3543a781 21 closedir(d);
yokoland95 2:05fe3543a781 22
yokoland95 2:05fe3543a781 23
yokoland95 2:05fe3543a781 24 FILE *fp = fopen("/local/form.csv", "r");
yokoland95 2:05fe3543a781 25 if(!fp) {
yokoland95 2:05fe3543a781 26 error("Could not open file!\n\r");
yokoland95 2:05fe3543a781 27 }
yokoland95 2:05fe3543a781 28
yokoland95 2:05fe3543a781 29
yokoland95 2:05fe3543a781 30 char ligne[500];
yokoland95 2:05fe3543a781 31 char* morceau;
yokoland95 2:05fe3543a781 32 /*-------------------------------------------*/
yokoland95 2:05fe3543a781 33 /* COMPTE LE NOMBRE DE LIGNE DANS LE FICHIER */
yokoland95 2:05fe3543a781 34 /*-------------------------------------------*/
yokoland95 2:05fe3543a781 35 printf("nombre de ligne %d\n\r", nb = nombre_ligne_fichier(fp));
yokoland95 2:05fe3543a781 36
yokoland95 2:05fe3543a781 37 for( i = 2; i <= nb; i++){
yokoland95 2:05fe3543a781 38 /*-----------------------------------*/
yokoland95 2:05fe3543a781 39 /* RETOURNE LE CONTENU DE LA LIGNE X */
yokoland95 2:05fe3543a781 40 /*-----------------------------------*/
yokoland95 2:05fe3543a781 41 retourne_ligne(i,ligne,fp);
yokoland95 2:05fe3543a781 42 printf("ligne %d est %s\n\r",i,ligne);
yokoland95 2:05fe3543a781 43
yokoland95 2:05fe3543a781 44 /*-----------------------------------*/
yokoland95 2:05fe3543a781 45 /* RETOURNE L'ÉLÉMENT X DE LA LIGNE */
yokoland95 2:05fe3543a781 46 /*-----------------------------------*/
yokoland95 2:05fe3543a781 47 morceau = retourne_element_ligne(1, ligne);
yokoland95 2:05fe3543a781 48 printf("la question est: %s \n\r", morceau);
yokoland95 2:05fe3543a781 49
yokoland95 2:05fe3543a781 50 /*-----------------------------------*/
yokoland95 2:05fe3543a781 51 /* RETOURNE L'ÉLÉMENT X DE LA LIGNE */
yokoland95 2:05fe3543a781 52 /*-----------------------------------*/
yokoland95 2:05fe3543a781 53 for(j = 1; j < 5; j++){
yokoland95 2:05fe3543a781 54 morceau = retourne_element_ligne(j+1, ligne);
yokoland95 2:05fe3543a781 55 printf("Reponse %d: %s \n\r",j, morceau);
yokoland95 2:05fe3543a781 56 }
yokoland95 2:05fe3543a781 57
yokoland95 2:05fe3543a781 58 /*----------------------------------------*/
yokoland95 2:05fe3543a781 59 /* RETOURNE LA BONNE REPONSE DE LA LIGNE */
yokoland95 2:05fe3543a781 60 /*----------------------------------------*/
yokoland95 2:05fe3543a781 61 j = num_bonne_reponse(ligne);
yokoland95 2:05fe3543a781 62 morceau = retourne_element_ligne(j+1, ligne);
yokoland95 2:05fe3543a781 63 printf("bonne reponse est la %d: %s \n\r",j, morceau);
yokoland95 2:05fe3543a781 64
yokoland95 2:05fe3543a781 65 /*-----------------------------------*/
yokoland95 2:05fe3543a781 66 /* RETOURNE L'ÉLÉMENT X DE LA LIGNE */
yokoland95 2:05fe3543a781 67 /*-----------------------------------*/
yokoland95 2:05fe3543a781 68 morceau = retourne_element_ligne(7, ligne);
yokoland95 2:05fe3543a781 69 printf("la raison: %s \n\r", morceau);
yokoland95 2:05fe3543a781 70 }
yokoland95 2:05fe3543a781 71 fclose(fp);
yokoland95 2:05fe3543a781 72
yokoland95 2:05fe3543a781 73 }