Lectura/escritura de cadena de caracteres en fichero.

Dependencies:   mbed

main.cpp

Committer:
jangelgm
Date:
2017-03-09
Revision:
0:22b21b6e33dc

File content as of revision 0:22b21b6e33dc:

/* 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
}