Parse GPS String for Time and Coordinates

Code

#include <stdio.h>
#include <string.h>

void parse_gprmc(char *nmea) {
    nmea=nmea+7;
    printf("Time: %.2s:%.2s:%.2s\n",nmea,nmea+2,nmea+4);
    nmea = nmea+9;
    printf("Latitude: %.8s %c\n",nmea,nmea[9]);
    nmea = nmea+11;
    printf("Longitude: %.9s %c",nmea,nmea[10]);
    return;
}

int main() {
    char nmea[100];
    fgets(nmea, sizeof(nmea), stdin);
    parse_gprmc(nmea);
    return 0;
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

$GPRMC,123519,A,4807.038,N,01131.000,E

Expected Output

Time: 12:35:19 Latitude: 4807.038 N Longitude: 01131.000 E