顺序表插入问题!!诡异的错误
#include<stdio.h>
#define MAXSIZE 100
typedef struct node
{
char s[MAXSIZE];
int len;
}NODE;
int insert(NODE *sql,int a,char x)
{
int k;
if (a<1||a>sql->len)
{
printf("the input is error !");
return 0;
}
if (sql->len>=MAXSIZE)
{
printf("the biao is full !");
}
for (k=sql->len;k>=a;k--)
{
sql->s[k+1]=sql->s[k];
}
sql->s[k+1]=x;
sql->len++;
return 1;
}
int main()
{
NODE seq;
int i,j;
char m;
printf("please input the length :");
scanf("%d",&seq.len);
printf("please input the insert position :");
scanf("%d",&i);
fflush(stdin);
printf("please input the insert value :");
scanf("%c",&m);
fflush(stdin);
printf("please input the first value :");
for (j=0;j<seq.len;j++)
{
scanf("%c",&seq.s[j]);
fflush(stdin);
}
insert(&seq,i,m);
for (j=0;j<seq.len;j--)
{
printf("%c",seq.s[j]);
}
return 1;
}
帮我看看到底哪里有问题啊
[解决办法]
错在下面这句,应为j++
for (j=0;j<seq.len;j--)
{
printf("%c",seq.s[j]);
}