#include <stdio.h> #include <string.h> void parse_gprmc(char *nmea) { // Your logic here /* 0 gprmc 1 time 2 status 3 lat 4 ns 5 long 6 ew */ char *fields[7]; int i = 0; char *help = strtok(nmea, ","); while(help != NULL){ fields[i++] = help; help = strtok(NULL, ","); } char *t = fields[1]; printf("Time: %.2s:%.2s:%.2s\nLatitude: %s %s\nLongitude: %s %s", t, t+2, t+4, fields[3], fields[4], fields[5], fields[6]); } int main() { char nmea[100]; fgets(nmea, sizeof(nmea), stdin); parse_gprmc(nmea); return 0; }
Test Cases
Test Results
Input
$GPRMC,123519,A,4807.038,N,01131.000,E
Expected Output
Time: 12:35:19 Latitude: 4807.038 N Longitude: 01131.000 E