Révision 649
Ajouté par megoutteno il y a presque 4 ans
branch/Gouttenoire/sp4a12/main.c | ||
---|---|---|
// fonction conversion latitude en flottant
|
||
float conver_latitude(char * ch)
|
||
{
|
||
float lat_s=0,lat_f=0,x=0;
|
||
int cpt=0,nb=10,i=0,c=0;
|
||
float lat_s=0,lat_f=0,x=0,lat_s_2=0;
|
||
int cpt=0,i=0,c=0,cpt_2=0;
|
||
while(ch[i]!= '.')
|
||
{
|
||
i++;
|
||
cpt++;
|
||
}
|
||
i=0;
|
||
while(ch[i]!='\0')
|
||
{
|
||
i++;
|
||
cpt_2++;
|
||
}
|
||
c=decode_nombre(ch,2);
|
||
for(i=0;i<cpt;i++)
|
||
{
|
||
lat_s=10*lat_s+decode_int(ch[i]);
|
||
}
|
||
for(i=cpt-2;i<=nb;i++)
|
||
for(i=cpt+1;i<cpt_2;i++)
|
||
{
|
||
x=(10*lat_s+decode_int(ch[i]))/(pow(10,nb-6));
|
||
lat_s_2=lat_s_2*10+decode_int(ch[i]);
|
||
}
|
||
lat_f= (lat_s-c*pow(10,cpt-2))/60+c;
|
||
return lat_s;
|
||
}
|
||
lat_s=lat_s+(lat_s_2/pow(10,cpt+1));
|
||
|
||
lat_f= ((lat_s-c*pow(10,cpt-2))/60)+c;
|
||
return lat_f;
|
||
}
|
||
// fonction conversion longitude en flottant
|
||
float conver_longitude(char * ch)
|
||
{
|
||
float lat_s=0,lat_f=0,x=0,lat_s_2=0;
|
||
int cpt=0,i=0,c=0,cpt_2=0;
|
||
while(ch[i]!= '.')
|
||
{
|
||
i++;
|
||
cpt++;
|
||
}
|
||
i=0;
|
||
while(ch[i]!='\0')
|
||
{
|
||
i++;
|
||
cpt_2++;
|
||
}
|
||
c=decode_nombre(ch,3);
|
||
for(i=0;i<cpt;i++)
|
||
{
|
||
lat_s=10*lat_s+decode_int(ch[i]);
|
||
}
|
||
for(i=cpt+1;i<cpt_2;i++)
|
||
{
|
||
lat_s_2=lat_s_2*10+decode_int(ch[i]);
|
||
}
|
||
lat_s=lat_s+(lat_s_2/pow(10,cpt+1));
|
||
|
||
lat_f= ((lat_s-c*pow(10,cpt-3))/60)+c;
|
||
return lat_f;
|
||
}
|
||
//fonction regroupant la conversion latitude et la conversion longitude
|
||
float latitude_longitude(char * ch)
|
||
{
|
||
int cpt=0;
|
||
|
||
while(ch[cpt]!='\0')
|
||
{
|
||
cpt++;
|
||
}
|
||
if(cpt==10)
|
||
{
|
||
conver_longitude(ch);
|
||
}
|
||
else
|
||
{
|
||
conver_latitude(ch);
|
||
}
|
||
|
||
}
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
void tests_unitaires(void){
|
||
|
||
... | ... | |
printf ("Erreur Test unitaire decode_nombre.\n");
|
||
exit(-1);
|
||
}
|
||
if (conver_latitude("7501.20000")!=75.02){
|
||
|
||
if (conver_latitude("7501.20000")<0.95*75.02 || conver_latitude("7501.20000")>1.05*75.02){
|
||
printf ("Erreur Test unitaire conver_latitude.\n");
|
||
exit(-1);
|
||
}
|
||
if (conver_longitude("7501.20000")<0.95*750.02 || conver_longitude("7501.20000")>1.05*750.02 ){
|
||
printf ("Erreur Test unitaire conver_longitude.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
if (latitude_longitude("7501.20000")<0.95*750.02 || latitude_longitude("7501.20000")>1.05*750.02 ){
|
||
printf ("Erreur Test unitaire latitude_longitude.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
}
|
Formats disponibles : Unified diff
Réalisation fonction longitude latitude et mise en commun des 2 fonctions (Fin Tp1)