鱼C论坛

 找回密码
 立即注册
查看: 2827|回复: 10

求各位大神解答这种错误是什么原因???

[复制链接]
发表于 2018-3-15 21:27:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
什么原因????
QQ图片20180315212551.png
QQ图片20180315212720.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-3-15 21:54:07 | 显示全部楼层
上代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-3-16 07:40:30 From FishC Mobile | 显示全部楼层
括起来
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-3-16 09:41:34 | 显示全部楼层

#include<stdio.h>
#include<malloc.h>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
#define INIT_SIZE 5
#define INCREM 5
#define ERROR 0
#define OK 1
typedef&nbsp;&nbsp;int ElemType;
typedef struct {&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//×
&nbsp; &nbsp; &nbsp; &nbsp; ElemType *slist;
&nbsp; &nbsp; &nbsp; &nbsp; int length;
&nbsp; &nbsp; &nbsp; &nbsp; int listsize;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //×&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//不知道定义来干嘛
}Sqlist;
int InitList_sq(Sqlist *L);
int CreateList_sq(Sqlist *L,int n);&nbsp;&nbsp;
int ListInsert_sq(Sqlist *L,int i,ElemType e);
int PrintList_sq(Sqlist *L);
int ListDelete_sq(Sqlist *L,int i);
void ListLocate(Sqlist *L,ElemType e);

//初始化顺序表(建立空表)
int InitList_sq(Sqlist *L){
&nbsp; &nbsp; &nbsp; &nbsp; L.slist=(ElemType*)malloc(INIT_SIZE*sizeof(ElemType));
&nbsp; &nbsp; &nbsp; &nbsp; if(!L.slist) return ERROR;
&nbsp; &nbsp; &nbsp; &nbsp; L.length=0;
&nbsp; &nbsp; &nbsp; &nbsp; // L.listsize=INIT_SIZE; //不知道什么用处
&nbsp; &nbsp; &nbsp; &nbsp; return OK;
}


//创建顺序表
int CreateList_sq(Sqlist *L,int n){
&nbsp; &nbsp; &nbsp; &nbsp; ElemType e;
&nbsp; &nbsp; &nbsp; &nbsp; int i;
&nbsp; &nbsp; &nbsp; &nbsp; for(i=0;i<n;i++)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("input data %d:",i+1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%d",&e);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /*&nbsp;&nbsp;if(!ListInsert_sq(L,i+1,e))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ERROR;&nbsp;&nbsp;*/
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; return OK;
}

// 输出顺序表中的元素
int PrintList_sq(Sqlist *L){
&nbsp; &nbsp; &nbsp; &nbsp; int i;
&nbsp; &nbsp; &nbsp; &nbsp; for(i=1;i<=L.length;i++)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("%5d",L.slist[i-1]);
&nbsp; &nbsp; &nbsp; &nbsp; return OK;
}

//在顺序表中插入
int ListInsert_sq(Sqlist *L,int i,ElemType e)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int k;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(i<1||i>L.length+1)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ERROR;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(k=L.length-1;k>=i-1;k--)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; L.slist[k+1]=L.slist[k];
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; L.slist[i-1]=e;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; L.length++;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return OK;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return OK;
&nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; //在顺序中删除第i个元素
int ListDelete_sq(Sqlist *L,int i)
{
&nbsp; &nbsp; &nbsp; &nbsp; int j;
&nbsp; &nbsp; &nbsp; &nbsp; if((i<1)||(i >L.length))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ERROR;
&nbsp; &nbsp; &nbsp; &nbsp; for(j=i;j<=L.length-1;j++)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; L.slist[j-1] =L.slist[j];
&nbsp; &nbsp; &nbsp; &nbsp; --L.length;
&nbsp; &nbsp; &nbsp; &nbsp; return OK;
}

//在顺序表中查找指定值元素,返回其序号
void ListLocate(Sqlist *L,ElemType e)
{
&nbsp; &nbsp; &nbsp; &nbsp; int i,z=0;
&nbsp; &nbsp; &nbsp; &nbsp; for(i=0;i<L.length-1;i++)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(L.slist==e)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("该值所在表中的序号为:第%d位",i+1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z=1;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; if(z==0)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("没有该值\n");
}

//主函数
int main()
{
&nbsp; &nbsp; &nbsp; &nbsp; Sqlist sl,L;
&nbsp; &nbsp; &nbsp; &nbsp; int n,i,e;
&nbsp; &nbsp; &nbsp; &nbsp; printf("*********************欢迎来到该界面******************");
&nbsp; &nbsp; &nbsp; &nbsp; printf("please input n(输入顺序表个数):");
&nbsp; &nbsp; &nbsp; &nbsp; scanf("%d",&n);
&nbsp; &nbsp; &nbsp; &nbsp; if(n>0)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\n1-Create Sqlist:\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InitList_sq(&sl);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CreateList_sq(&sl,n);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("输入要插入的值和序号:");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%d %d",&i,&e);&nbsp;&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListInsert_sq(&sl,i,e);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("输出插入后的顺序表:");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PrintList_sq(&sl);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("输入要删除的值元素的序号:");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%d",&i);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListDelete_sq(&sl,i);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("输出删除后的元素的顺序表:\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PrintList_sq(&sl);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("输入要查找的值:");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%d",&e);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListLocate(&sl, e);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; else
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("ERROR");
&nbsp; &nbsp; &nbsp; &nbsp; return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-3-16 09:43:19 | 显示全部楼层

刚才那个发错了 不知道为啥复制过去是那样的...
应该是下面这个


#include<stdio.h>
#include<malloc.h>                 
#define INIT_SIZE 5
#define INCREM 5
#define ERROR 0
#define OK 1
typedef  int ElemType;
typedef struct {               //×
        ElemType *slist;
        int length;
        int listsize;          //×        //不知道定义来干嘛
}Sqlist;
int InitList_sq(Sqlist *L);
int CreateList_sq(Sqlist *L,int n);  
int ListInsert_sq(Sqlist *L,int i,ElemType e);
int PrintList_sq(Sqlist *L);
int ListDelete_sq(Sqlist *L,int i);
void ListLocate(Sqlist *L,ElemType e);

//初始化顺序表(建立空表)
int InitList_sq(Sqlist *L){
        L.slist=(ElemType*)malloc(INIT_SIZE*sizeof(ElemType));
        if(!L.slist) return ERROR;
        L.length=0;
        // L.listsize=INIT_SIZE; //不知道什么用处
        return OK;
}


//创建顺序表
int CreateList_sq(Sqlist *L,int n){
        ElemType e;
        int i;
        for(i=0;i<n;i++)
        {
                printf("input data %d:",i+1);
                scanf("%d",&e);
                /*  if(!ListInsert_sq(L,i+1,e))
                        return ERROR;  */
        }
        return OK;
}

// 输出顺序表中的元素
int PrintList_sq(Sqlist *L){
        int i;
        for(i=1;i<=L.length;i++)
                printf("%5d",L.slist[i-1]);
        return OK;
}

//在顺序表中插入
int ListInsert_sq(Sqlist *L,int i,ElemType e)
        {
                int k;
                if(i<1||i>L.length+1)
                        return ERROR;
                else
                {
                        for(k=L.length-1;k>=i-1;k--)
                                L.slist[k+1]=L.slist[k];
                        L.slist[i-1]=e;
                        L.length++;
                        return OK;
                }
                return OK;
        }

        //在顺序中删除第i个元素
int ListDelete_sq(Sqlist *L,int i)
{
        int j;
        if((i<1)||(i >L.length))
                return ERROR;
        for(j=i;j<=L.length-1;j++)
                L.slist[j-1] =L.slist[j];
        --L.length;
        return OK;
}

//在顺序表中查找指定值元素,返回其序号
void ListLocate(Sqlist *L,ElemType e)
{
        int i,z=0;
        for(i=0;i<L.length-1;i++)
        {
                if(L.slist==e)
                        printf("该值所在表中的序号为:第%d位",i+1);
                z=1;
        }
        if(z==0)
                printf("没有该值\n");
}

//主函数
int main()
{
        Sqlist sl,L;
        int n,i,e;
        printf("*********************欢迎来到该界面******************");
        printf("please input n(输入顺序表个数):");
        scanf("%d",&n);
        if(n>0)
        {
                printf("\n1-Create Sqlist:\n");
                InitList_sq(&sl);
                CreateList_sq(&sl,n);
                printf("输入要插入的值和序号:");
                scanf("%d %d",&i,&e);  
                ListInsert_sq(&sl,i,e);
                printf("输出插入后的顺序表:");
                PrintList_sq(&sl);
                printf("\n");
                printf("输入要删除的值元素的序号:");
                scanf("%d",&i);
                ListDelete_sq(&sl,i);
                printf("输出删除后的元素的顺序表:\n");
                PrintList_sq(&sl);
                printf("\n");
                printf("输入要查找的值:");
                scanf("%d",&e);
                ListLocate(&sl, e);
        }
        else
                printf("ERROR");
        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-3-16 09:46:45 | 显示全部楼层

成员运算符优先级不是已经很高了吗???
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-3-16 09:54:46 | 显示全部楼层
愿你 发表于 2018-3-16 09:46
成员运算符优先级不是已经很高了吗???

自增的也不低
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-3-16 09:58:21 | 显示全部楼层

成员比自增高。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-3-16 10:09:18 | 显示全部楼层
愿你 发表于 2018-3-16 09:58
成员比自增高。。。

ok, you win.
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-3-16 10:51:22 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-3-26 17:35:26 | 显示全部楼层
这主要是.运算符和->的差别。前者由结构体变量引用。而后者是由指向结构体的指针变量引用
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-25 14:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表