Oppgave 9.3a

Dependencies:   mbed

Committer:
Smashftw
Date:
Tue Oct 31 12:45:37 2017 +0000
Revision:
0:1f6251de28c3
Oppgave 9.3a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Smashftw 0:1f6251de28c3 1 #include "mbed.h"
Smashftw 0:1f6251de28c3 2 LocalFileSystem local("local");
Smashftw 0:1f6251de28c3 3 Serial pc(USBTX, USBRX);
Smashftw 0:1f6251de28c3 4
Smashftw 0:1f6251de28c3 5 int main()
Smashftw 0:1f6251de28c3 6 {
Smashftw 0:1f6251de28c3 7 FILE *fp = fopen("/local/treasure.txt", "r");
Smashftw 0:1f6251de28c3 8 if (fp == NULL) { // Feil i åpning av fil
Smashftw 0:1f6251de28c3 9 pc.printf("Feil i fopen\n");
Smashftw 0:1f6251de28c3 10 return 1;
Smashftw 0:1f6251de28c3 11 }
Smashftw 0:1f6251de28c3 12
Smashftw 0:1f6251de28c3 13 // Read file character by character - max 1000 chars
Smashftw 0:1f6251de28c3 14 int cnum = 0;
Smashftw 0:1f6251de28c3 15 int ch;
Smashftw 0:1f6251de28c3 16 while ((ch = fgetc(fp)) != EOF) {
Smashftw 0:1f6251de28c3 17 pc.putc(ch);
Smashftw 0:1f6251de28c3 18 wait_ms(20);
Smashftw 0:1f6251de28c3 19 cnum++;
Smashftw 0:1f6251de28c3 20 if (cnum > 999) {
Smashftw 0:1f6251de28c3 21 break;
Smashftw 0:1f6251de28c3 22 }
Smashftw 0:1f6251de28c3 23 }
Smashftw 0:1f6251de28c3 24 fclose(fp);
Smashftw 0:1f6251de28c3 25 return 0;
Smashftw 0:1f6251de28c3 26 }