C语言。。。。。。。。。。。。。。。。。。。。。。。。。。。。

#include
#include
#define OK 1
#define OVERFLOW 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct
{
int *elem;

int length;
int data[100];
int listsize;
}SqList;
int InitList(SqList &L)
{
L.elem=(int *)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L.elem)
exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}
int LocateList(SqList L,int m)
{
int k;
k=1;
while((k<=L.length)&&L.elem[k-1]!=m)
k++;
if(L.elem[k-1]==m )
return k;
else
return 0;
}
void main()
{
int i,m,p;
SqList L;
InitList(L);
printf("请输入表长:\n");
scanf("%d",&L.length);
printf("Please input the numbers:\n");
for(i=0;i<L.length;i++)
{ scanf("%d",&L.elem[i]);}
//输入一组数
printf("你输入的数字有:\n");
for(i=0;i<L.length;i++)
{ printf("% d",L.elem[i]);}
printf("\n请输入将要查找的数:\n");
scanf("%d",&m);
printf("该数的位置为:\n");
p=LocateList(L,m);
if(p == 0)
printf("there is no number in the SqList!\n");
else
printf("The number which you want to find is at the place of :%d\n",p);
}
如果输入数字时个数大于长度,该怎么让它报错。

最简单的 加个if条件不就可以啦。 先得到输入的数据长度是多少 判断是不是超过你的界限

判断scanf的返回值就可以了

判断L.length和你定义的最大值就好了,如果大于最大值就输出错误提示

输出提示信息呗,让用户重新输入

代码不对吧,好多错误啊