level 11
# include <stdio.h>
int iGreat;
struct Student
{
char cName[20];
int iNumber;
struct Student *pText;
};
struct Student *Great()
{
struct Student *pHead = NULL;
struct Student *pEnd, *pNew;
iGreat = 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)
{
iGreat++;
if (iGreat == 0)
{
pNew -> pText = NULL;
pNew -> pText = pHead;
pEnd = pNew;
}
else
{
pNew -> pText = NULL;
pEnd -> pText = 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 *pTmp;
int lindex = 1;
printf("____________the List has %d member:________\n", iGreat);
printf("\n");
pTmp = pHead;
while (pTmp != NULL)
{
printf("the number is : %d\n", lindex);
printf("the name is : %s\n", pTmp -> cName);
printf("the Number is : %d\n", pTmp -> iNumber);
printf("\n");
pTmp = pTmp -> pText;
lindex++;
}
}
int main(void)
{
struct Student *pHead;
pHead = Great(pHead);
print(pHead);
return 0;
2015年05月25日 11点05分