Tandin Wangchuk / Mbed 2 deprecated Lab3-01_Save_the_letters

Dependencies:   mbed SDFileSystem

main.cpp

Committer:
HEPTA
Date:
2017-09-07
Revision:
13:4fb761757895
Parent:
10:4d6870d0caa0
Child:
14:1c1a7c1f1228

File content as of revision 13:4fb761757895:

#include "mbed.h"
#include "SDFileSystem.h"

Serial pc(USBTX,USBRX);
SDFileSystem sd(p5, p6, p7, p8, "sd");

int main(){
    pc.baud(9600);
    pc.printf("Hello world!\r\n");
    char str[100];
    mkdir("/sd/mydir", 0777);
    FILE *fp = fopen("/sd/mydir/test.txt","w");
    if(fp == NULL) {
        error("Could not open file for write\r\n");
    }
    for(int i=0; i<10; i++)fprintf(fp,"Hello my name is HEPTA!\r\n");
    fclose(fp);
    fp = fopen("/sd/mydir/test.txt","r");
    fgets(str,100,fp);
    puts(str);
    fclose(fp);
    pc.printf("Goodbye!!\r\n");
}