I’ve used generic read and write examples that I find on the web, the issue is all the examples seem not to have a function declaration as they are used withing the small main body of the example.
I want to access these functions from other cpp modules so I need to include a declaration in a header file.
I cant seem to get the correct declaration format … help?
These are the two functions:
void writeFile(fs::FS &fs, const char * path, const char * message)
{}
String readFile(fs::FS &fs, const char * path)
{}
Create a file MyFileFunctions.h
:
#ifndef MY_FILE_FUNCTIONS_H // Include guard
#define MY_FILE_FUNCTIONS_H
#include <FS.h>
void writeFile(fs::FS &fs, const char * path, const char * message);
String readFile(fs::FS &fs, const char * path);
#endif // Include guard
Create a file MyFileFunctions.cpp
:
#include "MyFileFunctions.h
void writeFile(fs::FS &fs, const char * path, const char * message) {
// your code here
}
String readFile(fs::FS &fs, const char * path) {
// your code here
}
Now you can #include "MyFileFunctions.h"
from all your .cpp
files and make use of the functions writeFile()
and readFile()
.
There’s a good tutorial on youtube.