problem 7 for HW 2

Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

main.cpp

Committer:
lzzcd001
Date:
2015-02-18
Revision:
1:d8f90021eb1a
Parent:
0:bdbd3d6fc5d5

File content as of revision 1:d8f90021eb1a:

#include "mbed.h"
#include "SDFileSystem.h"
#include <string>
 
SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
 
int main() {
    printf("Hello World!\n");   
    //for(i=0; 1; i++) if(fgetc(file) == EOF) break;

    //fseek(file, 0, SEEK_SET);
    
    char *out = (char*) malloc(sizeof(char) * 100+1);
    mkdir("/sd/mydir", 0777);
    
    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
    if(fp == NULL) {
        error("Could not open file for write\n");
    }
    fprintf(fp, "Hello fun SD Card World!"); 
    
    FILE *fpd = fopen("/sd/sdtest.txt", "r");
    if(fp == NULL) {
        error("Could not open file for write\n");
    }
    fscanf(fpd,"%s",out);
    
    if(fp == NULL) {
        error("Could not open file for write\n");
    }
    fprintf(fp, out);
    fclose(fp); 
    fclose(fpd);
    printf("Goodbye World!\n");
}