CodeShare

Dependencies:   FatFileSystem mbed

Fork of 4180_Lab2_USB by Jeremy Cai

main.cpp

Committer:
jeremycai3721
Date:
2016-09-25
Revision:
1:fca955be2a5b
Parent:
0:4e756c4c88a7

File content as of revision 1:fca955be2a5b:

#include "mbed.h"
#include "MSCFileSystem.h"

MSCFileSystem fs ("fs");

int main () {

    FILE *fp = fopen("/fs/hello.txt","w");
    if ( fp == NULL )
    {
        error("Could not open file for write\n");
    }
    fprintf(fp, "Hello mass storage!\n\r");
    fclose (fp);
    printf("Goodbye World!\n\r");
    
    
    // example of reading a file one byte at a time
   // // and display it in hex format on the terminal

    unsigned char c;                          // a single byte buffer

    fp = fopen("/fs/hello.txt", "r");  // open the file in 'read' mode

    while (!feof(fp)) {                       // while not end of file
        c=fgetc(fp);                         // get a character/byte from the file
        printf("%c\r",c);                  //
    }
    printf("\n\r");
    fclose(fp);                               // close the file
}