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.
10 years, 7 months ago.
Problems with SD Card
I use this code
- include "SDCard.h"
- include "SDFileSystem.h"
- include "mbed.h"
- include <string>
- include <fstream>
extern Serial uartpc; extern SDFileSystem sd;
void SDC::init(){
mkdir("/sd/save", 0777);
return; }
void SDC::initread(string adress){ sprintf(readfile, "/sd/save/%sr.txt",adress); FILE *fp = fopen(readfile, "w"); fr.open(readfile, ios::in); }
void SDC::initwrite(string adress){ sprintf(writefile, "/sd/save/%sw.txt",adress); fw.open(writefile, ios::out); }
void SDC::SDwrite(int Sendvalue){ sprintf(Send,"Wert%s\r\n",Sendvalue); fprintf(fp, "Hello fun SD Card World!\r\n"); fw << "100\n"; uartpc.printf("Schreiben!!!"); return; }
void SDC::SDread(){
- _Out = 1; for(int i=0; i<200;i++){ getline(fr,s); } uartpc.printf("Read from file: %s",s);
- _Out = 0; return; }
void SDC::SDwclose(){ uartpc.printf("Schliessen!!!"); fw.close(); fclose(fp); uartpc.printf("Geschlossen!!!"); }
void SDC::SDrclose(){ fr.close(); }
The Problem was, that if i took the SD Card out of the Slot, there was nothing written in the File. But i closed it. (I used the fstream with fw << ...;) So i wanted to try the code with the pointer, But he saids that fp is doesnt known when i try to write or close. I think its a definition Problem but i cant solve it. I think the problem is because i initialize the stream in a function and the other funtions so does not know the stream *fp but how i can solve it?