Oppgave 9.3b

Dependencies:   mbed

main.cpp

Committer:
Smashftw
Date:
2017-10-31
Revision:
0:e3cc80ff6fe4

File content as of revision 0:e3cc80ff6fe4:

#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;
    while ((ch = fgetc(fp)) != EOF) {
       
        cnum++;
        if(cnum > 999) {
        pc.printf("Antall tegn: %d", ch);
        break;
       
        }
    }
   
    fclose(fp);
    return 0;
}