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:2944b34ee981

File content as of revision 0:2944b34ee981:

/* Program Example 10.2: Read and write text string data 
                                                             */
#include "mbed.h"
Serial pc(USBTX,USBRX);                // setup terminal link
LocalFileSystem local("local");        // define local file system
char write_string[64];                // character array up to 64 characters
char read_string[64];                                   // create character arrays (strings)                                
 
int main ()
{
  FILE* File1 = fopen("/local/textfile.txt","w");    // open file access
  fputs("lots and lots of words and letters", File1);// put text into file
  fclose(File1);                                     // close file
    
  FILE* File2 = fopen ("/local/textfile.txt","r");  // open file for reading
  fgets(read_string,256,File2);                      // read first data value
  fclose(File2);                                       // close file

  pc.printf("text data: %s \n",read_string);              // display read data string 
}