M
mdh
Hi All,
I understand atof is in the library, but this is part of my learning
curve.
Given
double atof( char *s){
double d = 0.00;
double sign = 1.00;
double fractprt = 1.00;
/* check for neg number */
if ( *s == '-') {
sign = -1.00;
s++;
}
while (isadigit(*s)){
d=d*10.00 + ('0' - *s++);
}
if (*s == '.'){
s++;
while(isadigit(*s)){
d=d*10.00 + ('0' - *s++);
fractprt *=10;
}
}
return (sign * d / fractprt) ;
}
where s[] equals -36.03, the return I get is 36.03 not -36.03. Is
there a reason why
"return (sign * d / fractprt) ;"
does not seem to multiply by "-1"
Thanks
I understand atof is in the library, but this is part of my learning
curve.
Given
double atof( char *s){
double d = 0.00;
double sign = 1.00;
double fractprt = 1.00;
/* check for neg number */
if ( *s == '-') {
sign = -1.00;
s++;
}
while (isadigit(*s)){
d=d*10.00 + ('0' - *s++);
}
if (*s == '.'){
s++;
while(isadigit(*s)){
d=d*10.00 + ('0' - *s++);
fractprt *=10;
}
}
return (sign * d / fractprt) ;
}
where s[] equals -36.03, the return I get is 36.03 not -36.03. Is
there a reason why
"return (sign * d / fractprt) ;"
does not seem to multiply by "-1"
Thanks