| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2315 人关注过本帖
标题:顺序表报错
只看楼主 加入收藏
lyxlzp
Rank: 2
等 级:论坛游民
帖 子:61
专家分:38
注 册:2016-10-20
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
顺序表报错
#include<stdio.h>
#include<windows.h>
#include<malloc.h>
int Initlist(Sqlist * L);
int Insert(Sqlist * L,int pos, ElemType val);
typedef struct{           //定义结构体
    char sno[9];
    char name[9];
    char sex;
    char major[20];
}student;
#define MAXSIZE 100
#define ElemType student
typedef struct{
    ElemType * elem;
    int length;
}Sqlist;
int menu_select()
{
    char c;
    do{
        system("cls");
        printf("\n ***********学生信息管理系统*****************");
        printf("\n ***        1、查找学生信息               ***");
        printf("\n ***        2、增加学生信息               ***");
        printf("\n ***        3、删除学生信息               ***");
        printf("\n ***        4、统计学生信息               ***");
        printf("\n ***        5、修改学生信息               ***");
        printf("\n ***        0、退出系统                   ***");
        printf("\n*********************************************\n");
        c=getchar();
    }while(c<'0'||c>'5');
    return(c-'0');
}
void main()
{
  int n=0;
  while(1)
  {switch(menu_select())
    {
        case 1:
            printf("此功能可以实现查找学生信息\n");
             system("pause");break;
        case 2:
            printf("此功能可以实现增加学生信息\n");
              Initlist(&Sqlist);break;
        case 3:
            printf("此功能可以实现删除学生信息\n");
          system("pause");break;
        case 4:
            printf("此功能可以实现统计学生信息\n");
          system("pause");break;
        case 5:
            printf("此功能可以实现修改学生信息\n");
             Insert(&Sqlist,5,int val);break;
        case 0:
            printf("谢谢使用本系统/n");
            exit(0);
    }
  }
}
int Initlist(Sqlist * L)
{ L->elem=(ElemType *)malloc(MAXSIZE*sizeof(ElemType));
  if(L->length==0)
      return (-1);
  else
      L->length=0;
   return (1);
}
int Insert(Sqlist * L,int pos, ElemType val)
{ if(L->length==MAXSIZE)
    return (-1);
  if(pos<1||pos>L->length)
      return (-1);
  for(int i=length-1;i<pos-1;i--)
  { L->elem[i]=L->elem[i-1];}
   L->elem[pos-1]=val;
   L->length++;
   return (1);
}

在主函数里没有正确调用,这个我知道,但是为啥会在函数声明那报错。


这是报错的内容
c:\users\l\desktop\xxxxglxt.c(4) : error C2143: syntax error : missing ')' before '*'
c:\users\l\desktop\xxxxglxt.c(4) : error C2143: syntax error : missing '{' before '*'
c:\users\l\desktop\xxxxglxt.c(4) : error C2059: syntax error : ')'
c:\users\l\desktop\xxxxglxt.c(5) : error C2143: syntax error : missing ')' before '*'
c:\users\l\desktop\xxxxglxt.c(5) : error C2143: syntax error : missing '{' before '*'
c:\users\l\desktop\xxxxglxt.c(5) : error C2059: syntax error : 'type'
c:\users\l\desktop\xxxxglxt.c(5) : error C2059: syntax error : ')'
c:\users\l\desktop\xxxxglxt.c(46) : warning C4013: 'Initlist' undefined; assuming extern returning int
c:\users\l\desktop\xxxxglxt.c(46) : error C2275: 'Sqlist' : illegal use of this type as an expression
        c:\users\l\desktop\xxxxglxt.c(17) : see declaration of 'Sqlist'
c:\users\l\desktop\xxxxglxt.c(55) : warning C4013: 'Insert' undefined; assuming extern returning int
c:\users\l\desktop\xxxxglxt.c(55) : error C2275: 'Sqlist' : illegal use of this type as an expression
        c:\users\l\desktop\xxxxglxt.c(17) : see declaration of 'Sqlist'
c:\users\l\desktop\xxxxglxt.c(55) : error C2059: syntax error : 'type'
c:\users\l\desktop\xxxxglxt.c(75) : error C2143: syntax error : missing ';' before 'type'
c:\users\l\desktop\xxxxglxt.c(75) : error C2143: syntax error : missing ';' before 'type'
c:\users\l\desktop\xxxxglxt.c(75) : error C2143: syntax error : missing ')' before 'type'
c:\users\l\desktop\xxxxglxt.c(75) : error C2143: syntax error : missing ';' before 'type'
c:\users\l\desktop\xxxxglxt.c(75) : error C2065: 'i' : undeclared identifier
c:\users\l\desktop\xxxxglxt.c(75) : warning C4552: '<' : operator has no effect; expected operator with side-effect
c:\users\l\desktop\xxxxglxt.c(75) : error C2059: syntax error : ')'
c:\users\l\desktop\xxxxglxt.c(76) : error C2143: syntax error : missing ';' before '{'
执行 cl.exe 时出错.

搜索更多相关主题的帖子: include 管理系统 system 结构体 信息 
2017-03-02 16:42
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:5 
#include<stdio.h>
#include<windows.h>
#include<malloc.h>
int Initlist(Sqlist * L);
int Insert(Sqlist * L,int pos, ElemType val);
错误很明显  此时 程序尚不能识别神马Sqlist 神马的

DO IT YOURSELF !
2017-03-02 17:06
chaoba
Rank: 1
等 级:新手上路
帖 子:20
专家分:5
注 册:2016-11-20
收藏
得分:0 
我们也才学顺序表
2017-03-03 09:26
chaoba
Rank: 1
等 级:新手上路
帖 子:20
专家分:5
注 册:2016-11-20
收藏
得分:5 
定义结构体放到最前面,你那个插入语录好像有问题a[i+1]=a[i]

[此贴子已经被作者于2017-3-3 09:39编辑过]

2017-03-03 09:37
MyName180°
Rank: 2
等 级:论坛游民
帖 子:5
专家分:15
注 册:2017-2-16
收藏
得分:10 


#include<stdio.h>
#include<windows.h>
#include<malloc.h>

#define MAXSIZE 100
#define ElemType student


typedef struct{           //¶¨òå½á11ìå
    char sno[9];
    char name[9];
    char sex;
    char major[20];
}student;


typedef struct{
    ElemType * elem;
    int length;
}Sqlist;
Sqlist var_test;
ElemType stu = {"aaaaaaa","bbbbbbb",'c',"ddddddddddddd"};
int Initlist(Sqlist *L);
int Insert(Sqlist *L,int pos, ElemType val);
int menu_select()
{
    char c;
    do{
        system("cls");
        printf("\n ***********ѧéúDÅÏ¢1üàíÏμí3*****************");
        printf("\n ***        1¡¢2éÕòѧéúDÅÏ¢               ***");
        printf("\n ***        2¡¢Ôö¼óѧéúDÅÏ¢               ***");
        printf("\n ***        3¡¢é¾3yѧéúDÅÏ¢               ***");
        printf("\n ***        4¡¢í3¼ÆѧéúDÅÏ¢               ***");
        printf("\n ***        5¡¢DT¸ÄѧéúDÅÏ¢               ***");
        printf("\n ***        0¡¢íË3öÏμí3                   ***");
        printf("\n*********************************************\n");
        c=getchar();
    }while(c<'0'||c>'5');
    return(c-'0');
}
void main()
{
  int n=0;
  int var;
  while(1)
  {switch(menu_select())
    {
        case 1:
            printf("′Ë1|Äü¿éòÔêμÏÖ2éÕòѧéúDÅÏ¢\n");
             system("pause");break;
        case 2:
            printf("′Ë1|Äü¿éòÔêμÏÖÔö¼óѧéúDÅÏ¢\n");
              Initlist(&var_test);break;
        case 3:
            printf("′Ë1|Äü¿éòÔêμÏÖé¾3yѧéúDÅÏ¢\n");
          system("pause");break;
        case 4:
            printf("′Ë1|Äü¿éòÔêμÏÖí3¼ÆѧéúDÅÏ¢\n");
          system("pause");break;
        case 5:
            printf("′Ë1|Äü¿éòÔêμÏÖDT¸ÄѧéúDÅÏ¢\n");
             Insert(&var_test,5,stu);break;
        case 0:
            printf("D»D»ê1óñ¾Ïμí3/n");
            exit(0);
    }
  }
}
int Initlist(Sqlist * L)
{ L->elem=(ElemType *)malloc(MAXSIZE*sizeof(ElemType));
  if(L->length==0)
      return (-1);
  else
      L->length=0;
   return (1);
}
int Insert(Sqlist *L,int pos, ElemType val)
{
    int i;
    if(L->length==MAXSIZE)
    return (-1);
  if(pos<1||pos>L->length)
      return (-1);
  for(i=L->length-1;i<pos-1;i--)
  { L->elem[i]=L->elem[i-1];}
   L->elem[pos-1]=val;
   L->length++;
   return (1);
}


改好的你自己看吧
2017-03-03 11:39
lyxlzp
Rank: 2
等 级:论坛游民
帖 子:61
专家分:38
注 册:2016-10-20
收藏
得分:0 
回复 5楼 MyName180°
谢谢
2017-03-03 22:06
快速回复:顺序表报错
数据加载中...
 
   



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

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