帮帮我!!!!!!!!
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>}
#define listsize 11
typedef int datatype;
typedef struct
{
datatype data[listsize];
int length;
}seqlist;
void creat(struct seqlist *l)
{
int i;
printf("for creat seqlist,input l->length=%d",l->length);
for(i=1;i<=l->length;i++)
scanf("%d",l->data+i);
printf("\n");
}
void main()
{
int i,c,k;
struct seqlist p;
clrscr();
p.length=m;
printf("\n creat seqlist \n");
creat(&p);
for (i=1;i<=p.length,i++)
printf("%d",p.data[i]);
printf("\n");
printf("\n for insert,input int c=? index k=? \n");
scanf("%d%d",&c,&k);
printf("\n")
insert_seqlist(&p,c,k);
for(i=1;i<=p.length;i++)
printf("%d",p.data[i]);
printf("\n");
getch();
}
void insertlist(seqlist *l,datatype x,int i)
{
int j;
if (i<1||i>l->length+1)
error("postion error");
if (l->length>=listsize)
error("overflow");
for (j=l->length-1;j>=i;j--)
l->data[j+1]=l->data[j];
l->data[i-1]=x;
l->length++;
}
这是我编写“插入顺序表”中在turbo c2.0中编写的程序,不过运行不出来!请大虾帮我看看!
显示error d:\study\c\shunbiao.c 18:undefined structure "seqlist" in function creat
error d:\study\c\shunbiao.c 22:undefined structure "seqlist" in function main
error d:\study\c\shunbiao.c 22:size of structure or array not known in function
请问是怎么回事?
问题点数:0、回复次数:7Top
1 楼abitz(阿奈)(老婆永远是对的!)回复于 2003-12-03 16:55:26 得分 0
错误太多,那里抄的Top
2 楼arfi()回复于 2003-12-03 17:09:39 得分 0
OK,现在还缺少一个error函数的定义,你把它替换成printf也行。有没有逻辑上的错误没有看。
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define listsize 11
typedef int datatype;
typedef struct
{
datatype data[listsize];
int length;
}seqlist;
void creat(seqlist *l)
{
int i;
printf("for creat seqlist,input l->length=%d",l->length);
for(i=1;i<=l->length;i++)
scanf("%d",l->data+i);
printf("\n");
}
void insertlist(seqlist *l,datatype x,int i);
void main()
{
int i,c,k;
seqlist p;
// clrscr();
p.length=listsize;
printf("\n creat seqlist \n");
creat(&p);
for (i=1;i<=p.length;i++)
printf("%d",p.data[i]);
printf("\n");
printf("\n for insert,input int c=? index k=? \n");
scanf("%d%d",&c,&k);
printf("\n");
insertlist(&p,c,k);
for(i=1;i<=p.length;i++)
printf("%d",p.data[i]);
printf("\n");
getch();
}
void insertlist(seqlist *l,datatype x,int i)
{
int j;
if (i<1||i>l->length+1)
error("postion error");
if (l->length>=listsize)
error("overflow");
for (j=l->length-1;j>=i;j--)
l->data[j+1]=l->data[j];
l->data[i-1]=x;
l->length++;
}Top
3 楼skywarship(很菜的小李)回复于 2003-12-03 17:09:41 得分 0
struct seqlist p;错了,之前已经定义这个结构体为"seqlist",直接写seqlist pTop
4 楼opengl3d(opengl3d)回复于 2003-12-03 17:22:30 得分 0
void creat(struct seqlist *l)
---------use seqlist *lTop
5 楼abitz(阿奈)(老婆永远是对的!)回复于 2003-12-03 17:29:16 得分 0
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define listsize 11
typedef int datatype;
typedef struct
{
datatype data[listsize];
int length;
}seqlist;
void creat( seqlist *l)
{
int i;
printf("for creat seqlist,input l->length=%d\n",l->length);
for(i=1;i<=l->length;i++)
scanf("%d",l->data+i);
printf("\n");
}
void error(char *err)
{
printf("%s\n", err);
}
void insert_list(seqlist *l,datatype x,int i)
{
int j;
if (i<1||i>l->length+1)
error("postion error");
if (l->length>=listsize)
error("overflow");
for (j=l->length;j>=i;j--)
l->data[j+1]=l->data[j];
l->data[i]=x;
l->length++;
}
void main()
{
int i,c,k;
seqlist p;
// clrscr();
printf("\ninput the length of list, must < 10\n");
scanf("%d", &p.length);
printf("\ncreat seqlist \n");
creat(&p);
for (i=1;i<=p.length;i++)
printf("%d ",p.data[i]);
printf("\n");
printf("\nfor insert,input int c=? index k=? \n");
scanf("%d%d",&c,&k);
printf("\n");
insert_list(&p,c,k);
for(i=1;i<=p.length;i++)
printf("%d ",p.data[i]);
printf("\n");
getch();
}Top
6 楼abitz(阿奈)(老婆永远是对的!)回复于 2003-12-03 17:30:44 得分 0
运行结果:
input the length of list, must < 10
5
creat seqlist
for creat seqlist,input l->length=5
1 2 3 4 5
1 2 3 4 5
for insert,input int c=? index k=?
8 3
1 2 8 3 4 5
Top
7 楼time19810(夏)回复于 2003-12-03 20:08:05 得分 0
谢谢大家!我做出来了!Top




