by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
main.cpp@0:2944b34ee981, 2013-05-24 (annotated)
- Committer:
- robt
- Date:
- Fri May 24 22:12:04 2013 +0000
- Revision:
- 0:2944b34ee981
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robt | 0:2944b34ee981 | 1 | /* Program Example 10.2: Read and write text string data |
robt | 0:2944b34ee981 | 2 | */ |
robt | 0:2944b34ee981 | 3 | #include "mbed.h" |
robt | 0:2944b34ee981 | 4 | Serial pc(USBTX,USBRX); // setup terminal link |
robt | 0:2944b34ee981 | 5 | LocalFileSystem local("local"); // define local file system |
robt | 0:2944b34ee981 | 6 | char write_string[64]; // character array up to 64 characters |
robt | 0:2944b34ee981 | 7 | char read_string[64]; // create character arrays (strings) |
robt | 0:2944b34ee981 | 8 | |
robt | 0:2944b34ee981 | 9 | int main () |
robt | 0:2944b34ee981 | 10 | { |
robt | 0:2944b34ee981 | 11 | FILE* File1 = fopen("/local/textfile.txt","w"); // open file access |
robt | 0:2944b34ee981 | 12 | fputs("lots and lots of words and letters", File1);// put text into file |
robt | 0:2944b34ee981 | 13 | fclose(File1); // close file |
robt | 0:2944b34ee981 | 14 | |
robt | 0:2944b34ee981 | 15 | FILE* File2 = fopen ("/local/textfile.txt","r"); // open file for reading |
robt | 0:2944b34ee981 | 16 | fgets(read_string,256,File2); // read first data value |
robt | 0:2944b34ee981 | 17 | fclose(File2); // close file |
robt | 0:2944b34ee981 | 18 | |
robt | 0:2944b34ee981 | 19 | pc.printf("text data: %s \n",read_string); // display read data string |
robt | 0:2944b34ee981 | 20 | } |
robt | 0:2944b34ee981 | 21 |