这个C语言里面有点地方不太明白~谁能告诉下~详细点好
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#define M 8
int xx[M];
int proc(char *str,int x,int y)
{
int sum;
int i=0;
char *p=str;
for(i=0;i<M;i++)
xx[i]=0;
sum=*p-'0'; /*就是这,*p指向的是字符串第一个字符吧?那*p-‘0’得到的是什么结果呢?*/
p++;
while(*p)
{
sum=sum*x+*p-'0'; /*同样看不懂~书上解释是将字符串转为int型数据,看不太明白额*/
p++;
}
i=0;
while(sum!=0)
{
xx[i]=sum%y;
sum=sum/y;
i++;
}
return i;
}
void main()
{
char str[6];
int i;
int n;
int x;
int y;
printf("Enter a string made up of '0' to '9' digits character:");
gets(str);
if(strlen(str)>5)
{
printf("Error:string too longer!,please input again!\n\n");
exit(0);
}
for(i=0;str[i];i++)
if(str[i]<'0'||str[i]>'9')
{
printf("Error:%c not is '0' to '9' digits character!\n\n",str[i]);
exit(0);
}
printf("The original string: ");
puts(str);
printf("\nINPUT x= ");
scanf("%d",&x);
printf("\nINPUT y= ");
scanf("%d",&y);
n=proc(str,x,y);
printf("\n%s is convered to",str);
for(i=n-1;i>=0;i--)
printf("%d",xx[i]);
}