#include <stdio.h>
#include <string.h>
void parse_gprmc(char *nmea) {
int cur_index=0;
int read_index=0;
int word_count=0;
char table[10][20] = {};
//1. Obtain the comma seperate values and put them into an array
while(nmea[cur_index]!='\0'){
if(nmea[cur_index] == ','){
for(int i=0; i<cur_index-read_index;i++){
table[word_count][i] = nmea[i+read_index];
}
read_index = cur_index+1;
word_count++;
}
cur_index++;
}
for(int i=0; i<cur_index-read_index;i++){
table[word_count][i] = nmea[i+read_index];
}
word_count++;
//2. Format the outputs of the array values
//2.1 Output time as xx:xx:xx (time is element table[1])
printf("Time: ");
for(int j=0;table[1][j]!='\0';j++){
if(j % 2==0 && j!= 0){
printf(":%c",table[1][j]);
}
else{
printf("%c", table[1][j]);
}
}
//2. Output Latitude + Direction
printf("\nLatitude: %s %s\n",table[3],table[4]);
//3. Output Longitude + Direction
printf("Longitude: %s %s\n",table[5],table[6]);
}
int main() {
char nmea[100];
fgets(nmea, sizeof(nmea), stdin);
parse_gprmc(nmea);
return 0;
}