请问这样改为啥不行呢?(在最后)
#include<stdio.h>#include<malloc.h>
#include<process.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFESASIBLE -1
#define OVERFLOW -2
//using namespace std;
typedef int ElemType;
typedef ElemType *Triplet;
typedef int Status;
Status InitTriplet (Triplet &T,ElemType v1,ElemType v2,ElemType v3)
{
T=(ElemType *)malloc(3 * sizeof (ElemType));
if(!T)exit (OVERFLOW);
T[0]=v1;T[1]=v2;T[2]=v3;
return OK;
}
Status DestroyTriplet(Triplet &T)
{
free(T);T=NULL;
return OK;
}
Status Get(Triplet T,int i,ElemType &e)
{
//cout<<"which datas are you want ?:"<<endl;
//cin>>i;
if(i<1||i>3)return ERROR;
e=T[i-1];
printf("%d",e);
return OK;
}
Status Put(Triplet &T,int i,ElemType e)
{
printf("which datas you want to change:");
scanf("%d",&i);
if(i<1||i>3)return ERROR;
T[i-1]=e;
printf("%d",T[i-1]);
return OK;
}
int main()
{
ElemType v1,v2,v3;
Triplet T;
int i;
int j;
int e;
printf("输入三个数,建立一个三元组\n");
scanf("%d%d%d",&v1,&v2,&v3);
if(InitTriplet ( T, v1, v2, v3)==OVERFLOW)
printf("分配失败,退出程序!");
else
do{
printf("\n1:取三元组第个元素\n");
printf("2:修改三元组第i个元素\n");
scanf("%d",&j);
switch(j)
{
case 1:
printf("请输入i的值i=");
scanf("%d",&i);
if(Get(T,i,e)==ERROR)
printf("分配空间失败");
else printf("the number you want is %d\n",e);break;
case 2:
printf("\n请输入i的值i=");
scanf("%d",&i);
if(Put(T,i,e)==ERROR) printf("the number you input is not corret\n");
else
printf("the number you changed is:%d,%d,%d",T[0],T[1],T[2]);break;
default: printf("输入选择出错!\n");
}
}
while(j!=0); //[b]为啥不可以将这两行去掉?
DestroyTriplet(T); //为啥不可以将这两行去掉?
return 0;
}