strcmp
char* strcpy1(char* strDest, char* strSrc)
{
if(strSrc == NULL)
return NULL;
char *i = strSrc;
char *j = strDest;
while(*i != '\0')
{
*j++ = *i++;
}
*j = '\0';
return strDest;
}
strstr
char* strstr(const char* s1, const char* s2)
{
int n;
if(*s2)
{
while(*s1)
{
for(n=0; *(s1+n) == *(s2+n); n++)
{
if(!*(s2+n+1))
return (char*)s1;
}
s1++;
}
return NULL;
}
else
return (char*)s1;
}
atof
double convertToFloat(char* str)
{
double num = 0.0;
int i = 0;
double t = 10;
bool isNegative = false;
bool firstPointFlag = false;
if(str == NULL)
return num;
if(str[i] == '-')
{
isNegative = true;
i++;
}
else if(str[i] == '+')
{
isNegative = false;
i++;
}
else if(str[i] < '0' && str[i] > '9')
{
return num;
}
while(str[i] != '\0')
{
if(str[i] >= '0' && str[i] <= '9')
{
if(t == 10)
{
num = num*t + str[i] - '0';
}
else
{
num += (str[i] - '0') * t;
t = t*0.1;
}
}
else if(str[i] == '.')
{
if(!firstPointFlag)
{
t = 0.1;
firstPointFlag = true;
}
else
{
//第二次遇到小数点
return isNegative ? (-1 * num) : num;
}
}
else
{
return isNegative ? (-1 * num) : num;
}
i++;
}
return isNegative ? (-1 * num) : num;
}