关于C语言的问题。编译没有问题,就是运行时进不了插入删除函数!程序如下:

来源:百度知道 编辑:UC知道 时间:2024/06/28 07:19:59
#define maxsize 100
#include<stdio.h>
typedef struct{
int a[maxsize];
int len;
}sqlist;

sqlist *create(){
sqlist *L;
int i,n;
printf("please enter a number thayt will dicide the room of the array\n");
scanf("%d",&n);
if(n<0||n>maxsize)printf("You have enter a illagle number,please enter again!");
else
{
printf("now create the array :\n");
for(i=0;i<n;i++)
(*L).a[i]=i*10;

(*L).len=n-1;
printf("The new array is :");
for( i=0;i<=(*L).len;i++)
{
printf(" a[%d]=%d",i,(*L).a[i]);

}
printf("\n");
}
return L;
}

void insert(sqlist *L,int loca,int number){
int j,i;
if(loca<0||loca>(*L).len)printf("Wr

那两个if else镶嵌有问题,我改后的程序段,试试看。

void insert(sqlist *L,int loca,int number)
{
int j,i;
if(loca<0||loca>(*L).len)printf("Wrong location!") ;
else
{
for(j=(*L).len;j>=loca;j--)
(*L).a[j]=(*L).a[j-1];
(*L).a[loca-1]=number;
(*L).len=(*L).len+1;
printf("The new array is :");
for( i=0;i<(*L).len;i++)
printf(" a[%d]=%d: ",i,(*L).a[i]);
printf("\n");
getch();
}
}

del(sqlist *L,int loc)
{
int i,k,e;
if(loc<0||loc>=(*L).len) printf("wrong location!");
else
{
e=(*L).a[loc-1];
printf("The location you want to delete is:\n ",loc);
printf(" the number you want to delete is : %d\n",(*L).a[loc-1]);
for( k=loc;k<(*L).len;k++)
(*L).a[k-1]=(*L).a[k];
(*L).len=(*L).len-1;
printf("Th