I would like to replace String with char*. (I don't want to use Progmem to free SRAM space). After some research, I know that I have to use strcpy and something different than readStringUntil('\n') but I have difficulties to put everything in a right way.
This code is working but I have (of course) memory problem when the number of lines in my file text is high (I have 7000 lines in the file I'd like to use).
int i=0;
File printFile;
String tableau[100]; // I know the exact number of lines in the file
printFile = SD.open("/test.txt");
if (!printFile) {
Serial.print("The text file cannot be opened");
while(1);
}
while (printFile.available()) {
tableau[i]= printFiletop100g.readStringUntil('\n');
i++;
}
printFileprenombretong.close();
Here the code with lots of mistakes
File printFile;
char *pointeur = NULL;
char tab[20];
int numberLines=10000;
int i=0;
printFile = SD.open("/test.txt");
if (!printFile) {
Serial.print("The text file cannot be opened");
while(1);
}
pointeur =malloc(numberLines * sizeof(char*));
for(i = 0; i < numberLines; i++)
{
pointeur[i] = malloc((strlen(rareg) + 1) * sizeof(char));
strcpy(pointeur[i],tab);
i++;
}
printFile.close();
// Then the free pointeur function.
A file txt looks like :
Hello
How are You
Good
12Years
Why
...
In the end I'd like pointer[0]="Hello" pointer[1]="How are you" ...
Thanks for your help.