// Test2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cassert>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vld.h>
using namespace std;
double Strtod(char *str, char **endstr)
{
double num1 = 0.0;
double num2 = 0.0;
double point = 0.1;
int sign = 1;
int len = strlen(str) + 1;
*endstr = new char[len];
memset(*endstr, 0, len);
if (*str == '-')
{
sign = -1;
++str;
}
if (!isdigit(*str))
{
strcpy(*endstr, str);
return 0.0;
}
while (*str && isdigit(*str))
{
if (*str == '.')
{
++str;
while (*str && isdigit(*str))
{
num2 += point * ((*str) - '0');
point *= 0.1;
++str;
}
strcpy(*endstr, str);
break;
}
else
{
num1 = 10 * num1 + *str - '0';
str++;
if (!*str || !isdigit(*str))
{
strcpy(*endstr, str);
break;
}
}
}
return (num1 + num2) * sign;
}
int Atoi(const char *pstr)
{
int sign = 1;
int num = 0;
while (*pstr == ' ' || *pstr == '/t')
{
pstr++;
}
if (*pstr == '-')
{
sign = -1;
pstr++;
}
while (*pstr)
{
if (*pstr >= '0' && *pstr <= '9')
{
num = 10 * num + *pstr - '0';
}
else
{
return num * sign;
}
pstr++;
}
return (num * sign);
}
double Atof(const char *pstr)
{
double sign = 1.0;
double num1 = 0.0;
double num2 = 0.0;
double point = 0.1;
while (*pstr == ' ' || *pstr == '/t')
{
pstr++;
}
if (*pstr == '-')
{
sign = -1;
pstr++;
}
while (*pstr)
{
if (*pstr == '.')
{
pstr++;
while (*pstr >= '0' && *pstr <= '9')
{
num1 += point * (*pstr - '0');
point *= 0.1;
pstr++;
}
}
else if (*pstr >= '0' && *pstr <= '9')
{
num2 = num2 * 10 + *pstr -'0';
}
else
{
return (num1 + num2) * (sign);
}
pstr++;
}
return (num1 + num2) * (sign);
}
int main( void )
{
char str[] = " -1234565kljh";
int num = Atoi(str);
cout<< num << endl;
char pstr[] = " 112adfaf3 43224.569877aa";
double n = Atof(pstr);
printf("%6.8f/n", n);
return 0;
}