| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 368 人关注过本帖
标题:请问这样改为啥不行呢?(在最后)
只看楼主 加入收藏
唐兵
Rank: 2
来 自:四川泸州合江
等 级:论坛游民
帖 子:150
专家分:12
注 册:2012-12-1
结帖率:82.05%
收藏
已结贴  问题点数:10 回复次数:1 
请问这样改为啥不行呢?(在最后)
#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;
}
搜索更多相关主题的帖子: include return 
2013-10-08 22:29
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:10 
单步试试

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2013-10-12 07:15
快速回复:请问这样改为啥不行呢?(在最后)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014599 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved