All submissions

Parse GPS String for Time and Coordinates

Code

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

void parse_gprmc(char *nmea) {
    // Your logic here
    if (strncmp(nmea, "$GPRMC", 6) != 0) {
        printf("UNVALID data.\n");
        return;
    }
    
    printf("Time: ");
    for(int i = 7; i  <= 12; i++){
        
       printf("%c", nmea[i]);
        if(i == 8 || i == 10){
            printf(":");
        }
    }

    printf("\nLatitude: ");
    for(int i = 16; i  <= 25; i++){
        if(i == 24 ){
            printf(" ");
        }
        else{
             printf("%c", nmea[i]);
        }
    }
        
        printf("\nLongitude: ");
    for(int i = 27; i  <= 37; i++){
        if(i == 36 ){
            printf(" ");
        }
        else{
             printf("%c", nmea[i]);
        }
       
        
    }
    }


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

Solving Approach

 

 

 

Loading...

Input

$GPRMC,123519,A,4807.038,N,01131.000,E

Expected Output

Time: 12:35:19 Latitude: 4807.038 N Longitude: 01131.000 E