How to store an array of doubles? As array of doubles, Strings or const char *? Then convert back to use?

This seems like an old, solved problem, but I can't find any simple answers. I'm reading latitude and longitude data as Strings from a file (about 50 points), but they are really double float numbers.

First, I want to find the min/max ranges. Then, later, I want to do some calculations on them. I don't really want to keep reading the file, so I want to put them in an array. But no matter what kind of array I use (3 examples below), the program crashes with stack errors.

const char *latArray[ptsN];
const char *lngArray[ptsN];
//  or
String      latArray[ptsN];
String      lngArray[ptsN];
//  or
double      latArray[ptsN];
double      lngArray[ptsN];

while( myFile.available() ) {
lineN++;
String  latGet = myFile.readStringUntil(',');
double dLat = StrngToDouble( latGet );
if( dLat < minLat )  minLat = dLat;
if( dLat > maxLat )  maxLat = dLat;

latArray[lineN] = latGet;         //  put in String array
//  or
latArray[lineN] = latGet.c_str(); //  put in const char * array
//  or
latArray[lineN] = dLat;           //  put in double array

String  lngGet = myFile.readStringUntil(',');
double dLng = StrngToDouble( lngGet );
if( dLng < minLng )  minLng = dLng;
if( dLng > maxLng )  maxLng = dLng;

lngArray[lineN] = lngGet;         //  put in String array
//  or
lngArray[lineN] = lngGet.c_str(); //  put in const char * array
//  or
lngArray[lineN] = dLng;           //  put in double array

String  tmp = myFile.readStringUntil('\n');
}

where

double StrngToDouble( String dblString ) {
double temp = strtod( dblString.c_str(), NULL );
return temp;
}

This can compile and work - EXCEPT for reading the arrays and calculating using the floats, no matter what type of arrays I try using. It just crashes. What's the best way to resolve this? Thanks, Rick

• You may be out of memory. What Arduino are you using? How large is lineN? How much RAM is statically allocated (the compiler tells you that)? – Edgar Bonet Jan 6 at 20:02
• I'm actually using a Wemos ESP32. The compiler says: Sketch uses 285032 bytes (27%) of program storage space. Maximum is 1044464 bytes. Global variables use 37092 bytes (45%) of dynamic memory, leaving 44828 bytes for local variables. Maximum is 81920 bytes. – Rick_CBR929RR Jan 6 at 20:07
• And lineN?... – Edgar Bonet Jan 6 at 20:09
• Simplify your program. Read the data and print out what you get. Don't do anything with arrays yet. Once you have it reading and converting fine you can look at creating the arrays and adding the data to them. To me it sounds like you may be having a buffer overrun. Too many entries being put into your arrays. – Majenko Jan 6 at 20:25
• And to back that up - the first thing you do in your loop is lineN++, so you start with slice 1 instead of slice 0. Do you then go to fill slice ptsN? That's one more slice than you have... – Majenko Jan 6 at 20:27