Oppgave 9.2a
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:d896dc6654aa
diff -r 000000000000 -r d896dc6654aa main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 31 12:44:26 2017 +0000 @@ -0,0 +1,29 @@ + +#include "mbed.h" +LocalFileSystem local("local"); +Serial pc(USBTX, USBRX); + +int main() +{ + char line[120]; + + 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 line by line - max 100 lines + int lnum = 0; + while (fgets(line, 115, fp) != NULL) { + pc.puts(line); + wait_ms(20); + lnum++; + if (lnum > 99) { + break; + } + } + fclose(fp); + return 0; +} +