![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
CodeShare
Dependencies: FatFileSystem mbed
Fork of 4180_Lab2_USB by
Diff: main.cpp
- Revision:
- 1:fca955be2a5b
- Parent:
- 0:4e756c4c88a7
diff -r 4e756c4c88a7 -r fca955be2a5b main.cpp --- a/main.cpp Mon Sep 13 14:20:21 2010 +0000 +++ b/main.cpp Sun Sep 25 19:04:39 2016 +0000 @@ -6,7 +6,26 @@ int main () { FILE *fp = fopen("/fs/hello.txt","w"); - fprintf(fp,"Hello world!\n"); + 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 } \ No newline at end of file