女健身教练有什么要求:c语言程序中的疑问! *s=k+"0"; 什么意思!!!

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/30 02:54:45
#include <stdio.h>

void fun(long m,char s)
{
long k,i=10,n=0;
while(m==0)
{
k=m;
while(k>=10)
{
k=k/i;
n++;
}
*s=k+"0";
s++;
while(n!=0)
{
k=k*10;
n--;
}
m=m-k;
}
*s='\0';
}

void main()
{
long x,i;
char s[10];
scanf("%ld",&x);
if(x>0)
{
fun(x,s);
printf("%s\n",s);
}
else
printf("x value error\n");
}

这个程序有3处错误!我没办法全找出来!
求救!!
帮我在程序后面加注释!谢谢!

fun的声明里把char s改为char *s
*s=k+"0"也是错的,此处s为char的指针,而“0“是字符串,不能赋于*s,应改为*s=k+'0'。

另外,k+'0',表示把k(k为0-9)转成相应的字符'0'-'9'