Below code uses strtok function to extract tokens from string by delimeter ','.
ex.
#include<stdio.h>
#include <string.h>
int main() {
char string[200] = "$GNGNS,103600.01,5114.51176,N,00012.29380,W,45.6,,,V*00";
// Extract the first token
char * token = strtok(string, ",");
// loop through the string to extract all other tokens
while( token != NULL ) {
printf( " %s\n", token ); //printing each token
token = strtok(NULL, ",");
}
return 0;
}
The output is
$GNGNS
103600.01
5114.51176
N
00012.29380
W
45.6
V*00
Here the null value ,,, between 45.6 and V*00 are ignored. How can I print all tokens eventhrough it is null? like:
$GNGNS
103600.01
5114.51176
N
00012.29380
W
45.6
V*00