Plymouth University UK SoCEM Staff / Mbed 2 deprecated SDFileSystem_HelloWorld

Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

main.cpp

Committer:
martinsimpson
Date:
2017-10-05
Revision:
2:886ae0153478
Parent:
0:bdbd3d6fc5d5
Child:
4:73d5d4c507c9

File content as of revision 2:886ae0153478:

#include "mbed.h"
#include "SDFileSystem.h"
 
SDFileSystem sd(D11, D12, D13, D10, "sd"); // the pinout on the mbed Cool Components workshop board

char myStr[128];

int main() {
    printf("Start to write!\n");   
 
    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 World!");
    fprintf(fp, "This is a second line");
    fprintf(fp, "and now a third line");
    fclose(fp); 
 
    printf("Finished writing and closed file\n");
    
    FILE *fp1 = fopen("/sd/mydir/sdtest.txt", "r");
    //fscanf(fp1, "%s", myStr);
    fgets(myStr, 12, fp1);
    printf("\t%s\n\r",myStr);
    fclose(fp1); 
}