Skip to content

Instantly share code, notes, and snippets.

@ibanezmatt13
Last active December 25, 2015 00:29
Show Gist options
  • Save ibanezmatt13/6888125 to your computer and use it in GitHub Desktop.
Save ibanezmatt13/6888125 to your computer and use it in GitHub Desktop.
#include <stdio.h>
char mystring[] = "$GPGGA,124321,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47"; //example first part of NMEA sentence
void main()
{
char time[7];
char identifier[20];
char latitude[10];
char north_south[2];
char longitude[10];
char east_west[2];
char lock[2];
char satellites[3];
float altitude;
if (sscanf(mystring, "%6[^,], %6[^,], %9[^,], %1[^,], %9[^,], %1[^,], %1[^,], %2[^,], %*[^,], %5[^,]", identifier, time, latitude, north_south, longitude, east_west, lock, satellites, &altitude) == 9)
{
printf("%s\n", identifier);
printf("%s\n", time);
printf("%s\n", latitude);
printf("%s\n", north_south);
printf("%s\n", longitude);
printf("%s\n", east_west);
printf("%s\n", lock);
printf("%s\n", satellites);
printf("%f\n", altitude);
getchar();
}
else
{
printf("FAIL!");
getchar();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment