But this wasn't quite correct either! What if I get some input like "-0 54 12.047"? After converting the degrees, I get zero, not negative zero. So I had to add even more code to check the original unconverted string to see if I had to change the sign. Not too hard in concept, but since the code already supported both numeric forms, and directions either prefix or postfix ("N 54 19 17.554 W 77 32 8.333" as well as "54 19 17.554N77 32 8.333W"), it took a little finagling to get everything right.
I should have just used yacc.