HEPTA-Sat Training 2017~2018 / Mbed 2 deprecated Lab3-01_Save_the_letters

Dependencies:   SDFileSystem mbed

Fork of Lab7-01_template by HEPTA-Sat Training 2017~2018

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SDFileSystem.h"
00003 
00004 Serial pc(USBTX,USBRX);
00005 SDFileSystem sd(p5, p6, p7, p8, "sd");
00006 
00007 int main()
00008 {
00009     pc.baud(9600);
00010     pc.printf("Hello world!\r\n");
00011     char str[100];
00012     mkdir("/sd/mydir", 0777);
00013     FILE *fp = fopen("/sd/mydir/test.txt","w");
00014     if(fp == NULL) {
00015         error("Could not open file for write\r\n");
00016     }
00017     for(int i=0; i<10; i++)fprintf(fp,"Hello my name is HEPTA!\r\n");
00018     fclose(fp);
00019     fp = fopen("/sd/mydir/test.txt","r");
00020     for(int j = 0; j < 10; j++) {
00021         fgets(str,100,fp);
00022         puts(str);
00023     }
00024     fclose(fp);
00025     pc.printf("Goodbye!!\r\n");
00026 }