[CODE]/* SpaceItoA.c -- 将数字转换成字符串
* Author: Space
* Date: 2007/07/04
* Version: 1.0
*/
#include<stdio.h>
void space_itoa(int input, char *output)
{
int tmp = 0;
int index = 0;
while(input != 0)
{
tmp = input % 10;
output[index++] = '0' + tmp;
output[index++] = ' ';
input /= 10;
}
output[index-1] = '\0';
}
int main(void)
{
int input = 0;
char output[128] = "\0";
char ch;
int index = 0;
int len = 0;
printf("Please enter a positive integer:\n");
while (scanf("%d", &input) != 1 || input <= 0)
{
while(ch = getchar() != '\n')
continue;
printf("Invalid input! Please try again:\n");
}
space_itoa(input, output);
len = strlen(output);
for(index = 0; index < len / 2; ++index)
{
ch = output[index];
output[index] = output[len - index - 1];
output[len - index - 1] = ch;
}
printf("Input: Integer format is %d!\n", input);
printf("Output: String format is %s!\n", output);
return 0;
}[/CODE]
看看这个符合你的要求不?