Code:
#include <stdio.h>
#include <stdlib.h> // atoi, atof
#include <string.h> // strchr
int main() {
//char msg[] = "GPGGA,172814.0,3723.46587704,N,12202.26957864,"
// "W,2,6,1.2,18.893,M,-25.669,M,2.0,0031*4F";
char msg[] = "GPGGA,,,,,,7,13,99.99,,,,,,*48";
float time=0, latitude=0, longitude=0, hdop=0, alt=0, geoid=0;
char ns='?', ew='?', unit='?';
int lock=0, sats=0;
char *p = strchr(msg, ',');
time = atof(p+1); // if field is empty this encounters a comma and returns 0.0
p = strchr(p+1, ',');
latitude = atof(p+1);
p = strchr(p+1, ',');
ns = p[1] == ',' ? '?' : p[1];
p = strchr(p+1, ',');
longitude = atof(p+1);
p = strchr(p+1, ',');
ew = p[1] == ',' ? '?' : p[1];
p = strchr(p+1, ',');
lock = atoi(p+1);
p = strchr(p+1, ',');
sats = atoi(p+1);
p = strchr(p+1, ',');
hdop = atof(p+1);
p = strchr(p+1, ',');
alt = atof(p+1);
p = strchr(p+1, ',');
unit = p[1] == ',' ? '?' : p[1];
p = strchr(p+1, ',');
geoid = atof(p+1);
printf("%f %f %c %f %c %d %d %f %f %c %f\n",
time, latitude, ns, longitude, ew, lock,
sats, hdop, alt, unit, geoid);
return 0;
}