ECE 4180 Lab 2 Part 13

Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Files at this revision

API Documentation at this revision

Comitter:
abraha2d
Date:
Tue Oct 09 00:52:07 2018 +0000
Parent:
1:e4d7342be507
Commit message:
Save point

Changed in this revision

SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/SDFileSystem.lib	Tue May 16 05:18:55 2017 +0000
+++ b/SDFileSystem.lib	Tue Oct 09 00:52:07 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/SDFileSystem/#8db0d3b02cec
+https://os.mbed.com/users/abraha2d/code/SDFileSystem/#3dbddda953bb
--- a/main.cpp	Tue May 16 05:18:55 2017 +0000
+++ b/main.cpp	Tue Oct 09 00:52:07 2018 +0000
@@ -1,19 +1,55 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
- 
-SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
- 
-int main() {
-    printf("Hello World!\n");   
- 
+
+SDFileSystem sd(p11, p12, p13, p14, "sd"); // the pinout on the mbed Cool Components workshop board
+
+FILE * pFile;
+long lSize;
+char * buffer;
+size_t result;
+
+int main()
+{
+    printf("Hello World!\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 fun SD Card World!");
-    fclose(fp); 
- 
+    fprintf(fp, "Hello SD file world");
+    fclose(fp);
+
+    pFile = fopen ( "/sd/mydir/sdtest.txt" , "r" );
+    if (pFile==NULL) {
+        error ("File error");
+    }
+
+    // obtain file size:
+    fseek (pFile , 0 , SEEK_END);
+    lSize = ftell (pFile);
+    rewind (pFile);
+
+    // allocate memory to contain the whole file:
+    buffer = (char*) malloc (sizeof(char)*lSize);
+    if (buffer == NULL) {
+        error ("Memory error");
+    }
+
+    // copy the file into the buffer:
+    result = fread (buffer,1,lSize,pFile);
+    if (result != lSize) {
+        error ("Reading error");
+        exit (3);
+    }
+
+    /* the whole file is now loaded in the memory buffer. */
+    printf(buffer);
+
+    // terminate
+    fclose (pFile);
+    free (buffer);
+
     printf("Goodbye World!\n");
 }
--- a/mbed.bld	Tue May 16 05:18:55 2017 +0000
+++ b/mbed.bld	Tue Oct 09 00:52:07 2018 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/mbed_official/code/mbed/builds/e1686b8d5b90
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file