求助 ·这程序问题出在哪阿· 我看了好几天都不知道错在哪
小弟不胜感激阿···#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<malloc.h>
#define MAXS 50
struct Triple{
int i,j;
int e;
};
struct TSM {
struct Triple data[MAXS];
int mu,nu,tu;
};
void input(struct TSM *T)
{ int r=0;
printf("mn: ");scanf("%d",&T->mu);
printf("nu: ");scanf("%d",&T->nu);
printf("tu: ");scanf("%d",&T->tu);
printf("\n");
for(r=0;r<T->tu;r++)
{ printf("i: ");
scanf("%d",&T->data[r].i);
printf("j: ");
scanf("%d",&T->data[r].j);
printf("e: ");
scanf("%d",&T->data[r].e);
printf("\n");
}
}
void print(struct TSM *T)
{int i=0,j=0,r=0;
for(i=0;i<T->mu;i++)
{ printf("\n");
for(j=0;j<T->nu;j++)
{if(i==T->data[r].i&&j==T->data[r].j)
{printf(" %d ",T->data[r].e);r++;}
else printf(" 0 ");
}
printf("\n");
}
}
void add(struct TSM *A,struct TSM *B,struct TSM *C)
{ int r=0,k=0,c=0,ai,aj,bi,bj;printf("c==%d",A->data[r].e);
if(A->mu!=B->mu||A->nu!=B->nu)
exit(0);
else
C->mu=A->mu;C->nu=A->nu;
while(r<A->tu&&k<B->tu)
{
ai=A->data[r].i;aj=A->data[r].j;
bi=B->data[k].i;bj=B->data[k].j;
if(ai<bi)
{
C->data[c].e=A->data[r].e;printf("c==%d,%d",A->data[r].e,c)
C->data[c].i=A->data[r].i;
C->data[c].j=A->data[r].j;
r++; printf("*<* r=%d ",r);printf("k=%d ",k);
c++;printf("c==%d,%d",A->data[r].e,c);
}
else if(ai==bi)
{
if(aj==bj)
{
C->data[c].e=A->data[r].e+B->data[k].e;
C->data[c].i=A->data[r].i;
C->data[c].j=A->data[r].j;
r++;
c++;
k++;printf("*==*r=%d ",r);printf("k=%d ",k);printf("c==%d,%d",C->data[c].e,c);
}
else if(aj<bj)
{
C->data[c].e=A->data[r].e;
C->data[c].i=A->data[r].i;
C->data[c].j=A->data[r].j;
r++;c++;printf("*=<*r=%d ",r);printf("k=%d ",k);
printf("c==%d,%d",C->data[c].e,c);
}
else if(aj>bj)
{
C->data[c].e=B->data[k].e;
C->data[c].i=B->data[k].i;
C->data[c].j=B->data[k].j;
k++;c++;printf("*=>*r=%d ",r);printf("k=%d ",k);
printf("c==%d,%d",C->data[c].e,c);
}
}
else if(ai>bi)
{
C->data[c].e=B->data[k].e;
C->data[c].i=B->data[k].i;
C->data[c].j=B->data[k].j;
k++;c++;printf("*>*r=%d ",r);printf("k=%d ",k);
printf("c==%d,%d",C->data[c].e,c);
}
}
while(k<B->tu)
{
C->data[c].e=B->data[k].e;
C->data[c].i=B->data[k].i;C->data[c].j=B->data[k].j;
k++;c++;printf("*b*r=%d ",r);printf("k=%d ",k);
printf("c==%d,%d",C->data[c].e,c);
}
while(r<A->tu)
{
C->data[c].e=A->data[r].e;
C->data[c].i=A->data[r].i;C->data[c].j=A->data[r].j;
r++;c++;printf("*a*r=%d ",r);printf("k=%d ",k);
printf("c==%d,%d",C->data[c].e,c);
}printf("*ziji*r=%d ",r);printf("k=%d ",k);
printf("c==%d,%d",C->data[c].e,c);
}
void main()
{struct TSM *A,*B,*C;
clrscr();
printf(" =========the game begin==========\n");
memset(A,0,sizeof(struct TSM));
memset(B,0,sizeof(struct TSM));
memset(C,0,sizeof(struct TSM));
input(A);
printf("\n A= \n");
print(A);
printf("\n");
input(B);
printf("\n B= \n");
print(B);
printf("\n");
add(A,B,C);
printf("\n so have A+B= \n");
print(C);
printf("\n =========the game over==========");
}