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) {
    // Your logic here
    char delim=',';
    int i=0;
    int timeind=0;
    nmea+=6;
    while(*nmea){
        if(*nmea==delim) {
            switch(i){
                case 0: printf("Time: "); break;
                case 1: break;
                case 2: printf("\nLatitude: "); break;
                case 3: printf(" "); break;
                case 4: printf("\nLongitude: "); break;
                case 5: printf(" "); break;
                default: break;
            }
            i++;nmea++;
            continue;
        }
        if(timeind!=6)
        printf("%c",*nmea); // to not print A
        timeind++;
        if(timeind==2||timeind==4) printf(":");
        nmea++;
    }
}

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

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote