Hi,
I wrote a small code to convert string into double. Code is as follow
double stof(char *i_str)
{
char *firstPart = NULL;
char *secondPart = NULL;
double outPut;
if(i_str[0] != '.') {
firstPart = strtok(i_str, "."
secondPart = &i_str[ strlen(firstPart) + 1 ];
outPut = (double)atoi(firstPart) + ((double)atoi(secondPart)) / (pow(10, strlen(secondPart)));
}
else {
firstPart = '\0';
secondPart = &i_str[ 1 ];
outPut = 0.0 + ((double)atoi(secondPart)) / (pow(10, strlen(secondPart)));
}
return outPut;
}
It's taking a sting input like "102.433" and returning a double having a value 102.433. But there is no error Handle in this function. Can anyone suggest me to put some error handler in that function with different type of inputs( valid or invalid )...
--Amar
I wrote a small code to convert string into double. Code is as follow
double stof(char *i_str)
{
char *firstPart = NULL;
char *secondPart = NULL;
double outPut;
if(i_str[0] != '.') {
firstPart = strtok(i_str, "."
secondPart = &i_str[ strlen(firstPart) + 1 ];
outPut = (double)atoi(firstPart) + ((double)atoi(secondPart)) / (pow(10, strlen(secondPart)));
}
else {
firstPart = '\0';
secondPart = &i_str[ 1 ];
outPut = 0.0 + ((double)atoi(secondPart)) / (pow(10, strlen(secondPart)));
}
return outPut;
}
It's taking a sting input like "102.433" and returning a double having a value 102.433. But there is no error Handle in this function. Can anyone suggest me to put some error handler in that function with different type of inputs( valid or invalid )...
--Amar