102. Parse GPS String for Time and Coordinates

Back To All Submissions
Previous Submission
Next Submission

Code

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

void parse_gprmc(char *nmea) {
    char *field[7];
    int index=0;

    char *token=strtok(nmea, ",");
    while(token!=NULL&&index<7){
        field[index++]=token;
        token=strtok(NULL,",");
    }
    char *t=field[1];
    printf("Time: %.2s:%.2s:%.2s\n",t,t+2,t+4);
    printf("Latitude: %s %s\n", field[3],field[4]);
    printf("Longitude: %s %s", field[5],field[6]);
}


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

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote