I am trying to compile a C program named " atof" (ref: Kernigham ritchie,second edition "The C programing language", pg 71). using a microsoft visual c++ compiler - version 6.
THe problem which I am getting is that when I compile and run the program for the value 1.234 (of the input string) and executing it, the results are fine. but when I am debugging the same frogram using the f10 and f11 keys the result printed is as follows:
-1.#IND000000000.
can any one explain this mystry.
here is the entire code for quick reference:
/* atof: converts string to double*/
#include <stdio.h>
#include<ctype.h>
#define MAX 10
double atof(char x[]);
main()
{
char s[MAX];
printf("pls enter the string you want to convert to a double\n"
scanf("%s",s);
printf("%f",atof(s));
}
double atof(char s[])
{
double val,power;
int i,sign;
for(i=0;isspace(s);i++)/*skip white spaces*/
;
sign = (s=='-')? -1:1;
if (s=='+'||s=='-')
i++;
for(val=0.0;isdigit(s);i++)
val=10.0*val+(s-'0');
if(s=='.')
i++;
for (power=1.0;isdigit(s);i++)
{
val = 10.0*val+(s-'0');
power *=10.0;
}
return sign*val/power;
}
THe problem which I am getting is that when I compile and run the program for the value 1.234 (of the input string) and executing it, the results are fine. but when I am debugging the same frogram using the f10 and f11 keys the result printed is as follows:
-1.#IND000000000.
can any one explain this mystry.
here is the entire code for quick reference:
/* atof: converts string to double*/
#include <stdio.h>
#include<ctype.h>
#define MAX 10
double atof(char x[]);
main()
{
char s[MAX];
printf("pls enter the string you want to convert to a double\n"
scanf("%s",s);
printf("%f",atof(s));
}
double atof(char s[])
{
double val,power;
int i,sign;
for(i=0;isspace(s);i++)/*skip white spaces*/
;
sign = (s=='-')? -1:1;
if (s=='+'||s=='-')
i++;
for(val=0.0;isdigit(s);i++)
val=10.0*val+(s-'0');
if(s=='.')
i++;
for (power=1.0;isdigit(s);i++)
{
val = 10.0*val+(s-'0');
power *=10.0;
}
return sign*val/power;
}