求助有关链表的问题 输出的时候多了一个零
#define _CRT_SECURE_NO_WARNINGS#include "stdio.h"
#include "stdlib.h"
#include "string.h"
typedef struct Node
{
int data;
struct Node* next;
}SLIST;
SLIST* List_Create();
int List_Print(SLIST* pHead);
SLIST* List_Create()
{
int num = 0;
SLIST* pHead = NULL;
SLIST* pCur = NULL;
while (num != -1)
{
SLIST* pM = (SLIST*)malloc(sizeof(SLIST));
pM->data = num;
pM->next = NULL;
if (pHead == NULL)
{
pHead = pCur = pM;
}
else
{
pCur->next = pM;
pCur = pM;
}
printf("请输入num的值:");
scanf("%d", &num);
}
printf("num的值为-1,存值结束");
return pHead;
}
void main()
{
SLIST* pHead = NULL;
pHead = List_Create();
List_Print(pHead);
system("pause");
}
int List_Print(SLIST* pHead)
{
SLIST* p = NULL;
for (p = pHead; p; p = p->next)
{
printf("%d ", p->data);
}
printf("\n");
}