by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   mbed

main.cpp

Committer:
robt
Date:
2013-05-24
Revision:
0:965fcc0691fd

File content as of revision 0:965fcc0691fd:

/* Program Example 10.1: read and write char data bytes
                                                             */
#include "mbed.h"
Serial pc(USBTX,USBRX);               // setup terminal link
LocalFileSystem local("local");      // define local file system
int write_var;
int read_var;                           // create data variables

int main ()
{
  FILE* File1 = fopen("/local/datafile.txt","w");       // open file
  write_var=0x23;                                       // example data
  fputc(write_var, File1);               // put char (data value) into file
  fclose(File1);                       // close file  

  FILE* File2 = fopen ("/local/datafile.txt","r");  // open file for reading
  read_var = fgetc(File2);                            // read first data value
  fclose(File2);                                      // close file
  pc.printf("input value = %i \n",read_var);     // display read data value 
}