10 years, 7 months ago.

Problems with SD Card

I use this code

  1. include "SDCard.h"
  2. include "SDFileSystem.h"
  3. include "mbed.h"
  4. include <string>
  5. 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?

Be the first to answer this question.