将Str转换成Int
int StrToInt(char str[])
{
int i=0;
int isNeg = 0;
int num =0;
if(str[0]=='-')
{
isNeg = 1;
i =1;
}
while(str[i])
{
num*=10;
num+= (str[i++]-'0');
}
if(isNeg)
num*= -1;
return num;
}
将Int转换成Str
#define MAX_DIGITIS_INT 10
void IntToStr(int num, char str[])
{
int i=0,j=0,isNeg=0;
char temp[MAX_DIGITIS_INT + 2];
if(num<0)
{
num*=-1;
isNeg =1;
}
do
{
temp[i++] = (num%10)+'0';
num /= 10;
}while(num);
if(isNeg)
temp[i++]= '-';
while(i>0)
str[j++] = temp[--i];
str[j]='\0';
}