I am trying to make my own string tokenizer and I am failing miserably. Its a GPS parsing problem. I have my sample code below but I can't get it to compile. I am horrible with pointers and I have a feeling that is where the problem is. Can someone help me to work my way through this please?
char buffer[] = "GPGGA,205952.987,4041.2358,N,07406.5601,W,1,05,1.9,12.1,M,-34.2,M,,0000*5C";
char messageID[6];
char time[11];
char latit[10];
char NS[2];
char longit[11];
char EW[2];
char fixindicator[2];
char satsUsed[3];
char HDOP[4];
char MSLalt[10];
char Units[2];
char Geoid[6];
char GeoUnits[2];
void setup()
{
Serial.begin(115200);
}
void loop()
{
int idx = 0;
idx = mytok(buffer, idx, ',', &messageID);
idx = mytok(buffer, idx, ',', &time);
idx = mytok(buffer, idx, ',', &latit);
idx = mytok(buffer, idx, ',', &NS);
idx = mytok(buffer, idx, ',', &longit);
idx = mytok(buffer, idx, ',', &EW);
idx = mytok(buffer, idx, ',', &fixindicator);
idx = mytok(buffer, idx, ',', &satsUsed);
}
int mytok(const char *str, int idx = 0, char sep = ',', char *target)
{
while(str[idx] != sep) target++ = str[idx++];
return idx+1;
}