102. Parse GPS String for Time and Coordinates

Back To All Submissions
Previous Submission
Next Submission

Code

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

void parse_gprmc(char *nmea) {
    // Your logic here
    char *token = strtok(nmea,",");
    token=strtok(NULL,",");
    printf("Time: %.2s:%.2s:%.2s\n",token,token+2,token+4);
    strtok(NULL,",");
    char *lat = strtok(NULL,",");
    char *ns = strtok(NULL,",");
    char *lon = strtok(NULL,",");
    char *ew = strtok(NULL,",");

    printf("Latitude: %s %s\n", lat, ns);
    printf("Longitude: %s %s\n", lon,ew);
}

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

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote