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