#include<stdio.h>
#include<stdlib.h>
void y_atoi(int n, char s[]);
main(int argc, char *argv[])
{
int a = -23456;
char str[20];
/*
if(argc < 2)
{
fprintf(stderr, "No arguments!\n");
exit(-1);
}
*/
y_atoi(a, str);
printf("%s\n", str);
return 0;
}
/*y_atoi() turn a integer into a string*/
void y_atoi(int n, char s[])
{
int i, k;
int sign;
if((sign = n) < 0)
n = -n;
i = 1;
k = n;
while((k /= 10) > 0)
i++;//i mean the n has i digits
if(sign < 0) {// if n is negative, there must be a '-' at the first position
i++;
s[0] = '-';
}
s[i] = '\0';
do {
s[(i--)-1] = n%10 + '0';
}while((n /= 10) > 0);
}
整形转换成字符串输出
最新推荐文章于 2021-06-14 11:33:15 发布