problem 7 for HW 2

Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Files at this revision

API Documentation at this revision

Comitter:
lzzcd001
Date:
Wed Feb 18 14:52:56 2015 +0000
Parent:
0:bdbd3d6fc5d5
Commit message:
problem 7 for HW 2

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Dec 07 11:25:01 2012 +0000
+++ b/main.cpp	Wed Feb 18 14:52:56 2015 +0000
@@ -1,19 +1,35 @@
 #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!");
+    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");
 }