为什么我的程序总是调试失败 新手,求指教 有例子
为什么我的程序总是不能执行啊?#include<stdio.h>
#include<stdlib.h>
#define HUNTHOU 10000
typedef struct node{ int data;
struct node *next;
}NODE;
NODE *insert_after(NODE *u,int num);
NODE *addint(NODE *p,NODE *q);
void printint(NODE *s);
NODE *inputint(void);
NODE *insert_after(NODE *u,int num)
{
NODE *v;
v=(NODE *)malloc(sizeof(NODE));
v->data=num;
u->next=v;
return v;
}
NODE *addint(NODE *p,NODE *q)
{
NODE *pp,*qq,*r,*s,*t;
int total,number,carry;
pp=p->next; qq=q->next;
s=(NODE *)malloc(sizeof(NODE));
s->data=-1;
t=s; carry=0;
while(pp->data!=-1&&qq->data!=-1)
{
total=pp->data+qq->data+carry;
number=total%HUNTHOU;
carry=total/HUNTHOU;
t=insert_after(t,number);
pp=pp->next;
qq=qq->next;
}
r=(pp->data!=-1)?pp:qq;
while(r->data!=-1)
{
total=r->data+carry;
number=total%HUNTHOU;
carry=total/HUNTHOU;
t=insert_after(t,number);
r=r->next;
}
if(carry) t=insert_after(t,1);
t->next=s; return s; }
NODE *inputint(void) {
NODE *s,*ps,*qs;
struct number {int num;
struct number *np;
}*p,*q;
int i,k;
long sum;
char c;
p=NULL;
while((c=getchar())!='\n')
if(c>='0'&&c<='9')
{
q=(struct number *)malloc(sizeof(struct number));
q->num=c-'0';
q->np=p;
p=q;
}
s=(NODE *)malloc(sizeof(NODE));
s->data=-1;
ps=s;
while(p!=NULL)
{
sum=0;i=0;k=1;
while(i<4&&p!=NULL)
{
sum=sum+k*(p->num);
i++; p=p->np; k=k*10;
}
qs=(NODE *)malloc(sizeof(NODE));
qs->data=sum;
ps->next=qs;
ps=qs;
}
ps->next=s;
return s;
}
void printint(NODE *s)
{
if(s->next->data!=-1)
{
printint(s->next);
if(s->next->next->data==-1)
printf("%d",s->next->data);
else{
int i,k=HUNTHOU;
for(i=1;i<=4;i++,k/=10)
putchar('0'+s->next->data%(k)/(k/10));
}
}
}
void main()
{
NODE *s1,*s2,*s;
printf("Enter S1= ");
s1=inputint();
printf("Enter S2= ");
s2=inputint();
printf(" S1="); printint(s1); putchar('\n');
printf(" S2="); printint(s2); putchar('\n');
s=addint(s1,s2);
printf("S1+S2="); printint(s); putchar('\n');
}
这是一个用单循环链表来做长整数加法的问题,前面都没错误,可是到调试的时候有错误说外部函数有问题
求教
[ 本帖最后由 夜隐枯灯 于 2011-11-28 11:10 编辑 ]