Oppgave 9.3a

Dependencies:   mbed

Revision:
0:1f6251de28c3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 31 12:45:37 2017 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+LocalFileSystem local("local");
+Serial pc(USBTX, USBRX);
+
+int main()
+{
+    FILE *fp = fopen("/local/treasure.txt", "r");
+    if (fp == NULL) { // Feil i åpning av fil
+        pc.printf("Feil i fopen\n");
+        return 1;
+    }
+
+    // Read file character by character - max 1000 chars
+    int cnum = 0;
+    int ch;
+    while ((ch = fgetc(fp)) != EOF) {
+        pc.putc(ch);
+        wait_ms(20);
+        cnum++;
+        if (cnum > 999) {
+            break;
+        }
+    }
+    fclose(fp);
+    return 0;
+}