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 *x;

x = strtok(nmea+7,",");
printf("Time: %.2s:%.2s:%.2s\n",x,x+2,x+4);

x = strtok(NULL,",");

x = strtok(NULL,",");
printf("Latitude: %s ",x);
x = strtok(NULL,",");
printf("%s\n",x);

x = strtok(NULL,",");
printf("Longitude: %s ",x);
x = strtok(NULL,",");
printf("%s",x);
}

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

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote