#include <stdio.h> #include <ctype.h> void Myitoa(int n, char *s) { int i, j; int sign; int tmp; if((sign = n) < 0) n = -n; j = 0; while((i = n % 10)> 0) { s[j++] = i + ‘0‘;//整型转换成字符型 n = n / 10; } if(sign < 0) s[j] = ‘-‘; else j--; for(i = 0; i <= j / 2; i++) { tmp = s[i]; s[i] = s[j - i]; s[j - i] = tmp; } s[++j] = ‘\0‘; for(i = 0; i <= j; i++) printf("%c ", s[i]); } int main(void) { char str[20]; Myitoa(123458, str); printf("\n"); return 0; }
int型转字符串型函数itoa()实现,布布扣,bubuko.com
原文:http://blog.csdn.net/jjjcainiao/article/details/24328277