该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
代码如下:
#pragma warning(disable:4996)
#include
#include
struct Student
{
char cName[10];
int iNumber;
struct Student *pNext;
};
int iCloud;
struct Student *pHead = NULL;
struct Student *pEnd = NULL;
struct Student *Chuangjiang()
{
int Panduan;
struct Student *pNode = (struct Student *)malloc(sizeof(struct Student));
printf("请输入学生姓名,学号:\n");
scanf("%s", &pNode->cName);
scanf("%d", &pNode->iNumber);
pHead = pNode;
pNode->pNext = NULL;
while (pNode != NULL)
{
iCloud++;
if (iCloud == 1)
{
pHead = pNode;
}
else
{
pEnd->pNext = pNode;
}
pEnd = pNode;
printf("是否继续输入?");
scanf("%d", &Panduan);
if (Panduan == 0)
{
break;
}
scanf("%s", &pNode->cName);
scanf("%d", &pNode->iNumber);
}
return pHead;
}
void Print()
{
struct Student *pTemp = pHead;
while (pTemp != NULL)
{
printf("当前链表共有%d个数据!\n", iCloud);
printf("姓名:%s\t", pTemp->cName);
printf("姓名:%d\t", pTemp->iNumber);
pTemp= pTemp->pNext;
break;
}
}
int main()
{
struct Student *pHead;
pHead = Chuangjiang();
Print(pHead);
system("pause");
return 0;
}