Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Revision:
2:b86f4a4aa079
Parent:
0:bdbd3d6fc5d5
--- a/main.cpp	Tue May 16 05:18:55 2017 +0000
+++ b/main.cpp	Tue Oct 16 19:02:50 2018 +0000
@@ -1,19 +1,31 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
- 
+
+Serial pc(USBTX, USBRX);
 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
  
 int main() {
-    printf("Hello World!\n");   
- 
+    //Write to the file and close it 
     mkdir("/sd/mydir", 0777);
-    
     FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
     if(fp == NULL) {
         error("Could not open file for write\n");
+        pc.printf("fucccccckk");
     }
-    fprintf(fp, "Hello fun SD Card World!");
-    fclose(fp); 
+    fprintf(fp, "Hello SD World!");
+    fclose(fp);
+    
+    //Open the file and read out the data to the pc
+    fp = fopen("/sd/mydir/sdtest.txt", "r");
+    char Buffer[256];
  
-    printf("Goodbye World!\n");
+    if(fp == NULL) { error("Could not open file for reading\r\n"); }
+    
+    while(fgets (Buffer, 256, fp) != NULL){
+        Buffer[strlen(Buffer)-1] = 0;
+        pc.printf("\"%s\" \r\n", Buffer);
+     
+    }
+    
+    fclose(fp);
 }