Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
12 years, 2 months ago.
fseek and "r+" mode (random access)
Hi everyone
Any thoughts on how to do the same code below but for the localfilesystem instead? It works perfectly on the SD card. Pseudo: 1) Creates a file and stores "Hello World!\n" 2) Opens the file for changing in binary mode and replaces just the space between "Hello" and "World" by a hifen 3) Opens the file in read only and prints its contents
I don't want to change more than a single byte in an existing file (speed convenience).
/************
- include "mbed.h"
- include "SDHCFileSystem.h"
SDFileSystem sd(p11, p12, p13, p14, "sd"); mosi, miso, sclk, cs char buf[15];
Serial pc(USBTX, USBRX);
int main() { FILE *fp = fopen("/sd/myfile.txt", "w"); fprintf(fp, "Hello World!\n"); fclose(fp);
fp = fopen("/sd/myfile.txt", "rb+"); fseek(fp,5l,SEEK_SET); fputc('-',fp); fclose(fp);
fp = fopen("/sd/myfile.txt", "r"); fread(buf,12,1,fp); pc.printf("%s\n",buf); fclose(fp); } ************/
Thanks in advance.
Cheers