我日,你们也太专业了,还是新手,不能跟你们论了

一切从爱C开始
程序代码:
char *addfunc(char *addend, char *summand) //返回结果字符串的首地址
{
int len_add=0, len_sum=0;
char carry_flag=0, *temp=NULL, *result=NULL, *temp_sum=NULL;
char number=0;
if(strlen(addend)<strlen(summand)) //确保addend指向长字符串
{
temp=summand;
summand=addend;
addend=temp;
}
len_add=strlen(addend);
len_sum=strlen(summand);
result=(char*)malloc((len_add+2)*sizeof(char));
temp=result;
temp_sum=summand;
addend+=len_add-1;
summand+=len_sum-1;
while(len_add--)
{
if((*addend>'9')||(*addend<'0')||(*summand>'9')||(*summand<'0'))
{
printf("Input Error!\n");
exit(0);
}
if(len_sum>0)
{
number=*summand-'0'; // 转化位数字
len_sum--;
if(temp_sum!=summand)
summand--;
}
else
number=0;
*addend-='0';
*addend+=number;
if(carry_flag) //判断进位标志
{
*addend+=1;
carry_flag=0;
}
if(*addend>9)
{
carry_flag=1;
*addend-=10;
}
*temp++=*addend+'0';
addend--;
}
if(carry_flag)
*temp++='1';
*temp=NULL;
strrev(result);
return result;
}
