C语言
例如这个变元是25,就返回"25"。如果变元是-98,就返回"-98"。用适当MAIN函数说明函数执行过程
void itoa ( n,char *s)
{
int i = 0, j, temp, sign;
if((sign = n) < 0)
{
n = -n;
}
do
{
s[i++] = n%10 + '0';
}while ((n /= 10) > 0);
if(sign < 0)
s[i++] = '-';
s[i] = '\0';
for (j = 0; j < (i - 1)/2; j++)
{
temp = s[j];
s[j] = s[i - j - 1];
s[i - j - 1] = temp;
}
return;
}
{
int i = 0, j, temp, sign;
if((sign = n) < 0)
{
n = -n;
}
do
{
s[i++] = n%10 + '0';
}while ((n /= 10) > 0);
if(sign < 0)
s[i++] = '-';
s[i] = '\0';
for (j = 0; j < (i - 1)/2; j++)
{
temp = s[j];
s[j] = s[i - j - 1];
s[i - j - 1] = temp;
}
return;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2010-01-10
void IntToString(int num, char *pOutString)
{
if(pOutString)
sprintf(pOutString, "%s%d%s", "\"", num, "\"");
}
int main()
{
int a = 25;
char str[50];
IntToString(a, str);
printf("%s", str);
return 0;
}
{
if(pOutString)
sprintf(pOutString, "%s%d%s", "\"", num, "\"");
}
int main()
{
int a = 25;
char str[50];
IntToString(a, str);
printf("%s", str);
return 0;
}