How do I access individual chars in a pointer char array? I have an array which might look something like this:
064951.000
A
2307.1256
N
12016.443
E
0.03
165.48
260406
In the function calling my function in question:
char *parsedString[9];
getParsedString(parsedString);
size_t len = strlen(parsedString[3]);
pos.latitude = parseCoordinatePart(len, parsedString[3]);
Heres the function where I have problem understanding how to do:
double parseCoordinatePart(int len, char partArray[]){
if(len == 8){
degrees = 10 * partArray[0] - '0';
degrees += partArray[1] - '0';
}else if(len == 9){
indexAdd = 1;
degrees = 100 * partArray[0] - '0';
degrees += 10 * partArray[1] - '0';
degrees += partArray[2] - '0';
}
//More calculations to get longitude or latitude
}
While parseCoordinatePart() does not give any compile errors I can not call it from my function above. My first thought was to dereference parsedString[3] but anyway I tried it always gave me "illegal conversion of integer to pointer"
Update: Heres the code for setting parsedString data:
void splitNmeaString(char *parsedString[]){
char *token;
// remove the first token
token = strtok(receivedData, ",");
int tokenIndex = 0;
while( token != NULL )
{
token = strtok(NULL, ","); // works when 1st arg is NULL. But why?!
if(tokenIndex < 10 ){
parsedString[tokenIndex] = token;
}else{
break;
}
}
}
char *parsedString[9];?