数据结构,从键盘输入的问题


#include 
#include 
typedef  int ElemType;
typedef struct _seqList
{
    int* data;
    int len;
    int capacity;
}seqList;

void initList(seqList* L)
{
    L->capacity=8;
    L->len=0;
    L->data=(ElemType*)malloc(L->capacity*sizeof(ElemType));
}

void inversionList(seqList* L,int x)
{
    int temp=0;
    for(int i=0;i2;i++)
    {
        temp=L->data[i];
        L->data[i]=L->data[x-i-1];
        L->data[x-i-1]=temp;
        //swap(L->data[i],L->data[n-i]);
    }
    for(int i=0;i"%d ",L->data[i]);
    }
    printf("\n");

}
int main()
{
    seqList L;
    initList(&L);
    int n;
    scanf("%d",&n);
    int i=0;
    while(i"%d ",&L.data[i]);
        i++;
    }
    inversionList(&L,n);
    return 0;
}

为什么当n=5时,只有输入六位数才可以转换前五位数,输入五位数不可以。
inversionList的意思是倒置。

img

把scanf("%d ",&L.data[i]);中%d后面的空格去掉,不要在scanf函数的格式中随便加其他字符