为什么C语言在输入数据后多输出了一个数字才会输出结果

为什么C语言在输入数据后多输出了一个数字才会输出结果

img


#include 
#include 
#include 

typedef int ElemType;  
typedef struct LNode
{
    ElemType data;
    struct LNode * next;
}LNode,*pLinkList;
typedef LNode * PNode;

//创建带有头结点的空链表
pLinkList SetNullList_Link()
{
    pLinkList head = (pLinkList)malloc(sizeof(LNode)); //申请头结点空间
    if (head != NULL)
        head->next = NULL;
    else
        printf("申请头节点空间失败!\n");
    return head; //返回头指针
}

int IsNull_Link(pLinkList head) //判断链表是否为空,空返回1,非空返回0
{
    return(head->next == NULL);
} 
//1)初始化有序单链表L。
void CreatList(LNode*& L, int arry[], int length)
{
    L = (LNode*)malloc(sizeof(LNode));
    LNode* p, * pre, * s;
    s = L;
    for (int i = 0; i < 2; i++)
    {
        p = (LNode*)malloc(sizeof(LNode));
        p->data = arry[i];
        s->next = p;
        s = p;
    }
    L->next->next = NULL;
    for (int i = 1; i < length; i++)
    {
        p = (LNode*)malloc(sizeof(LNode));
        p->data = arry[i];
        pre = L;
        while (pre->next != NULL && pre->next->data < p->data){
            pre = pre->next;
        }
        p->next = pre->next;
        pre->next = p;
    }
}

void printList(pLinkList list)
{
    PNode  temp = list->next;
    int i = 0;
    while (temp)
    {
        printf("%d ", temp->data);
        temp = temp->next;
    }
    printf("\n");
}

int main()
{
    int Index;
    pLinkList L= NULL;
    L = SetNullList_Link();
    int num,arr[50];
    printf("输入初始化链表的元素个数:"); 
    scanf("%d",&num);
    printf("请输入数据(用空格分开):"); 
    for(int i=0;iscanf("%d ",&arr[i]);
    }
    CreatList(L,arr,num);
    printList(L);
    return 0;
}

scanf("%d ",&arr[i]);
把%d后面的空格删掉