Rob Toulson / Mbed 2 deprecated PE_10-02_ReadWriteString

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Program Example 10.2: Read and write text string data 
00002                                                              */
00003 #include "mbed.h"
00004 Serial pc(USBTX,USBRX);                // setup terminal link
00005 LocalFileSystem local("local");        // define local file system
00006 char write_string[64];                // character array up to 64 characters
00007 char read_string[64];                                   // create character arrays (strings)                                
00008  
00009 int main ()
00010 {
00011   FILE* File1 = fopen("/local/textfile.txt","w");    // open file access
00012   fputs("lots and lots of words and letters", File1);// put text into file
00013   fclose(File1);                                     // close file
00014     
00015   FILE* File2 = fopen ("/local/textfile.txt","r");  // open file for reading
00016   fgets(read_string,256,File2);                      // read first data value
00017   fclose(File2);                                       // close file
00018 
00019   pc.printf("text data: %s \n",read_string);              // display read data string 
00020 }
00021