#include <stdio.h>
#include <string.h>
void parse_gprmc(char *nmea) {
// Your logic here
int length = 0;
char token[7][10] = {0};
int i = 0, j = 0;
while (nmea[length] != '\0') {
if (nmea[length] != ',') {
token[i][j] = nmea[length];
j++;
}
else {
i++;
j = 0;
}
length++;
}
printf("Time: %c%c:%c%c:%c%c\n",token[1][0],token[1][1],token[1][2],token[1][3],token[1][4],token[1][5]);
printf("Latitude: %s %s\n",token[3],token[4]);
printf("Longitude: %s %s",token[5],token[6]);
}
int main() {
char nmea[100];
fgets(nmea, sizeof(nmea), stdin);
parse_gprmc(nmea);
return 0;
}
Input
$GPRMC,123519,A,4807.038,N,01131.000,E
Expected Output
Time: 12:35:19 Latitude: 4807.038 N Longitude: 01131.000 E