Last active
August 27, 2025 12:58
-
-
Save LightningStalker/339753de0502779da078ab358d081cf2 to your computer and use it in GitHub Desktop.
Convert sexagesimal GPS coordinates into decimal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Compile with gcc -Wall -o sex2dec sex2dec.c */ | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int main (int argc, char **argv) | |
| { | |
| if (argc == 5) | |
| { | |
| printf ("%f\n", atoi(argv[1]) | |
| + atoi(argv[2]) / 60.0 | |
| + atoi(argv[3]) / 3600.0 | |
| + atoi(argv[4]) / 216000.0); | |
| return (0); | |
| }else if (argc == 3) | |
| { | |
| printf ("%f\n", atoi(argv[1]) | |
| + atof(argv[2]) / 60.0); | |
| return (0); | |
| }else | |
| { | |
| puts ("\n sex2dec is a sexagesimal (base 60) to decimal converter."); | |
| puts (" sex2dec converts sexagesimal based deg/m/s/mils or deg/m.mmm coordinates into"); | |
| puts (" decimal."); | |
| puts (" use ABSOLUTE VALUE of any negative number, and garbage in = garbage out"); | |
| puts (" output is the coordinates in base 10"); | |
| puts (" sex2dec is not sexy.\n"); | |
| puts (" Usage: sex2dec degrees minutes seconds milliseconds"); | |
| puts (" Or: sex2dec degrees minutes.fraction"); | |
| puts (" Example: sex2dec 43 55 23 0"); | |
| puts (" Output should be: 43.923056\n"); | |
| return (1); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment