Oppgave 9.3c)
Dependencies: mbed
Revision 0:21a357bdbddf, committed 2017-10-31
- Comitter:
- Smashftw
- Date:
- Tue Oct 31 13:49:21 2017 +0000
- Commit message:
- Oppgave 93c;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 21a357bdbddf main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 31 13:49:21 2017 +0000 @@ -0,0 +1,51 @@ +#include "mbed.h" +LocalFileSystem local("local"); +Serial pc(USBTX, USBRX); + +int main() +{ + 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 character by character - max 1000 chars + int cnum = 0; + int ch; + int a, e, i, o ,u ,y; + while ((ch = fgetc(fp)) != EOF) { + ch |= (1 << 5); + cnum++; + if(ch == 0x61) { + a++; + } + else if(ch == 0x65) { + e++; + } + else if(ch == 0x69) { + i++; + } + else if(ch == 0x6F) { + o++; + } + else if(ch == 0x75) { + u++; + } + else if(ch == 0x79) { + y++; + } + + + } + pc.printf("Antall a: %d", a); + pc.printf("Antall e: %d", e); + pc.printf("Antall i: %d", i); + pc.printf("Antall o: %d", o); + pc.printf("Antall u: %d", u); + pc.printf("Antall y: %d", y); + fclose(fp); + return 0; +} +// Antall a: 23978 Antall e: 33597 Antall i: 39233 Antall o: 1073943710 Antall u: 29636 Antall y: 26958 \ No newline at end of file
diff -r 000000000000 -r 21a357bdbddf mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Oct 31 13:49:21 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/fb8e0ae1cceb \ No newline at end of file