You can find any number of DMS conversion functions in C/C++ on the web. Here is one I use.
void Split_into_dms(float angle, unsigned int * deg, unsigned int* min, float *sec) {
float t;
unsigned int d, m;
float s;
if (angle < 0.0) {
angle = - angle;
}
d = (unsigned int)angle;
t = (angle - (float )d)*60.0;
m = (unsigned int)(t);
s = (t - (float )m)*60.0;
/* Now some rounding issues */
if (s >= 59.995) {
s = 0.0;
m ++;
if (m == 60) {
m = 0;
d++;
}
}
*deg = d;
*min = m;
*sec = s;
}
It would be used like this:
float latitude, lat_sec;
unsigned int lat_deg, lat_min;
Split_into_dms(latitude, &lat_deg, &lat_min, &lat_sec);
You need to keep track yourself if the angle was negative and add the appropriate (W/S) prefix. Or you can modify the function to pass in a prefix pair (EW/NS) and return a single character prefix you need.