![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Oppgave 9.2b
Dependencies: mbed
main.cpp@0:1fb92a5d9c43, 2017-10-31 (annotated)
- Committer:
- Smashftw
- Date:
- Tue Oct 31 12:44:49 2017 +0000
- Revision:
- 0:1fb92a5d9c43
Oppgave 9.2b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Smashftw | 0:1fb92a5d9c43 | 1 | |
Smashftw | 0:1fb92a5d9c43 | 2 | #include "mbed.h" |
Smashftw | 0:1fb92a5d9c43 | 3 | LocalFileSystem local("local"); |
Smashftw | 0:1fb92a5d9c43 | 4 | Serial pc(USBTX, USBRX); |
Smashftw | 0:1fb92a5d9c43 | 5 | |
Smashftw | 0:1fb92a5d9c43 | 6 | int main() |
Smashftw | 0:1fb92a5d9c43 | 7 | { |
Smashftw | 0:1fb92a5d9c43 | 8 | char line[120]; |
Smashftw | 0:1fb92a5d9c43 | 9 | |
Smashftw | 0:1fb92a5d9c43 | 10 | FILE *fp = fopen("/local/treasure.txt", "r"); |
Smashftw | 0:1fb92a5d9c43 | 11 | if (fp == NULL) { // Feil i åpning av fil |
Smashftw | 0:1fb92a5d9c43 | 12 | pc.printf("Feil i fopen\n"); |
Smashftw | 0:1fb92a5d9c43 | 13 | return 1; |
Smashftw | 0:1fb92a5d9c43 | 14 | } |
Smashftw | 0:1fb92a5d9c43 | 15 | |
Smashftw | 0:1fb92a5d9c43 | 16 | // Read file line by line - max 100 lines |
Smashftw | 0:1fb92a5d9c43 | 17 | int lnum = 0; |
Smashftw | 0:1fb92a5d9c43 | 18 | for(lnum = 0; lnum < 999; lnum ++){ |
Smashftw | 0:1fb92a5d9c43 | 19 | fscanf(fp, "%*[^\n]\n"); |
Smashftw | 0:1fb92a5d9c43 | 20 | } |
Smashftw | 0:1fb92a5d9c43 | 21 | while (fgets(line, 159, fp) != NULL) { |
Smashftw | 0:1fb92a5d9c43 | 22 | |
Smashftw | 0:1fb92a5d9c43 | 23 | pc.puts(line); |
Smashftw | 0:1fb92a5d9c43 | 24 | wait_ms(20); |
Smashftw | 0:1fb92a5d9c43 | 25 | lnum++; |
Smashftw | 0:1fb92a5d9c43 | 26 | |
Smashftw | 0:1fb92a5d9c43 | 27 | if (lnum > 1049) { |
Smashftw | 0:1fb92a5d9c43 | 28 | break; |
Smashftw | 0:1fb92a5d9c43 | 29 | } |
Smashftw | 0:1fb92a5d9c43 | 30 | } |
Smashftw | 0:1fb92a5d9c43 | 31 | fclose(fp); |
Smashftw | 0:1fb92a5d9c43 | 32 | return 0; |
Smashftw | 0:1fb92a5d9c43 | 33 | } |
Smashftw | 0:1fb92a5d9c43 | 34 |