Parse GPS String for Time and Coordinates

Code

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

void parse_gprmc(char *nmea) {
    printf("Time: ");
    printf("%c%c:%c%c:%c%c\n", nmea[7],nmea[8],nmea[9],nmea[10],nmea[11],nmea[12]);
    printf("Latitude: %.*s %c\n", 8, nmea+16, nmea[25]);
    printf("Longitude: %.*s %c\n", 9, nmea+27, nmea[37]);
}

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