函数 提取出整数的每位数 C语言



用函数做,提取从键盘输入的一个整数的每位个数并转换成数字字符,在主函数中输出该字符串
不要用库函数。。在线等到1点半,写出来后百度HI我,谢谢~好的追加。。
PS可以不用指针么?。
#include <stdio.h>

/派数* 只是演示下思路,你可以简漏根据自己的需要拦羡烂设计 */
char *foo(char *s, int m, int n)
{
char *s1 = s + m - 1;
*s1 = 0;

do {
s1--;
*s1 = n % 10 + '0';
} while (n /= 10);

return s1;
}

int main(void)
{
char s[128];
int n;

scanf("%d", &n);
puts(foo(s, 128, n));

return 0;
}
代码供参考:
#include <stdio.h>磨慎
#include <string.h>
#include <信游哪stdlib.h>
void numtoch(int n,char s[]);
int main()
{
char s[10];
int n,i;
printf("请输入数字:");
scanf("%d",&n);
numtoch(n,s);
printf("转换后的字符串:");
for(i=0;i<strlen(s);i++)printf("%c ",s[i]);
printf("\n"滑码);
return 0;
}
void numtoch(int n,char s[])
{
itoa(n,s,10);
return ;
}