I have made a function that convert format of latitude and longitude from Degrees Minutes.m to Decimal Degrees.
For example:
latitude = 3130.1245 (Degrees Minutes.m) == 31.502075 (Decimal Degrees)
The problem is that I call this function twice with the same argument but it returns two different results. How is this happening?
Here is my code:
double Format(char *array){
double Degrees = 10*(array[0]-'0')+(array[1]-'0');
int i;
double z=0,N=10;
double x =0;
for(i=2;array[i]!='\0';i++){
if(array[i]=='.'){
for(i=i+1;array[i]!='\0';i++){
z=z+((array[i]-'0')/N);
N=N*10;
}
}
else
x=x*10+(array[i]-'0');
}
double Minutes = (x+z)/60 ;
return Degrees+Minutes ;
}
int main(){
char lat[]="3031.1234";
char lon[]="3031.1234";
double latitude ;
double longitude ;
latitude = Format(lat);
longitude = Format(lon);
printf("%lf\n",latitude); // output : 30.518723
printf("%lf\n",longitude); // output : 5247.185390
return 0 ;
}