#include <stdio.h>
#include <stdlib.h>
int iCount;
void Print(struct Student* pHead);
struct Student* Create();
int main()
{
struct Student* pHead;
pHead = Create();
Print(pHead);
return 0;
}
struct Student {
char cName[20];
int iNumber;
struct Student* pNext;
};
//创建链表函数
struct Student *Create()
{
struct Student *pHead = NULL;
struct Student *pEnd, *pNew;
iCount = 0;
pEnd = pNew = (struct Student*)malloc(sizeof(struct Student));
printf("please first enter Name,then Number\n");
scanf("%s",&pNew->cName);
scanf("%d", &pNew->iNumber);
while (pNew->iNumber!=0) {
iCount++;
if (iCount == 1) {
pNew->pNext = pHead;
pEnd = pNew;
pHead = pNew;
}
else {
pNew->pNext = NULL;
pEnd->pNext = pNew;
pEnd = pNew;
}
pNew = (struct Student*)malloc(sizeof(struct Student));
scanf("%s", &pNew->cName);
scanf("%d", &pNew->iNumber);
}
free(pNew);
return pHead;
};
//链表输出函数
void Print(struct Student *pHead) {
struct Student* pTemp;
int index=1;
printf("--------有%d个成员--------",iCount);
printf("\n");
pTemp = pHead;
while (pTemp!=NULL) {
printf("序号:%d\n",index);
printf("姓名:%s\n",pTemp->cName);
printf("学号:%d\n", pTemp->iNumber);
printf("-----------------------------\n");
pTemp = pTemp->pNext;
index++;
}
}