Oppgave 9.3b
Dependencies: mbed
main.cpp@0:e3cc80ff6fe4, 2017-10-31 (annotated)
- Committer:
- Smashftw
- Date:
- Tue Oct 31 12:53:19 2017 +0000
- Revision:
- 0:e3cc80ff6fe4
Oppgave93b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Smashftw | 0:e3cc80ff6fe4 | 1 | #include "mbed.h" |
Smashftw | 0:e3cc80ff6fe4 | 2 | LocalFileSystem local("local"); |
Smashftw | 0:e3cc80ff6fe4 | 3 | Serial pc(USBTX, USBRX); |
Smashftw | 0:e3cc80ff6fe4 | 4 | |
Smashftw | 0:e3cc80ff6fe4 | 5 | int main() |
Smashftw | 0:e3cc80ff6fe4 | 6 | { |
Smashftw | 0:e3cc80ff6fe4 | 7 | FILE *fp = fopen("/local/treasure.txt", "r"); |
Smashftw | 0:e3cc80ff6fe4 | 8 | if (fp == NULL) { // Feil i åpning av fil |
Smashftw | 0:e3cc80ff6fe4 | 9 | pc.printf("Feil i fopen\n"); |
Smashftw | 0:e3cc80ff6fe4 | 10 | return 1; |
Smashftw | 0:e3cc80ff6fe4 | 11 | } |
Smashftw | 0:e3cc80ff6fe4 | 12 | |
Smashftw | 0:e3cc80ff6fe4 | 13 | // Read file character by character - max 1000 chars |
Smashftw | 0:e3cc80ff6fe4 | 14 | int cnum = 0; |
Smashftw | 0:e3cc80ff6fe4 | 15 | int ch; |
Smashftw | 0:e3cc80ff6fe4 | 16 | while ((ch = fgetc(fp)) != EOF) { |
Smashftw | 0:e3cc80ff6fe4 | 17 | |
Smashftw | 0:e3cc80ff6fe4 | 18 | cnum++; |
Smashftw | 0:e3cc80ff6fe4 | 19 | if(cnum > 999) { |
Smashftw | 0:e3cc80ff6fe4 | 20 | pc.printf("Antall tegn: %d", ch); |
Smashftw | 0:e3cc80ff6fe4 | 21 | break; |
Smashftw | 0:e3cc80ff6fe4 | 22 | |
Smashftw | 0:e3cc80ff6fe4 | 23 | } |
Smashftw | 0:e3cc80ff6fe4 | 24 | } |
Smashftw | 0:e3cc80ff6fe4 | 25 | |
Smashftw | 0:e3cc80ff6fe4 | 26 | fclose(fp); |
Smashftw | 0:e3cc80ff6fe4 | 27 | return 0; |
Smashftw | 0:e3cc80ff6fe4 | 28 | } |