#include <stdio.h>
#include <stdlib.h>
int n = 0;
struct student
{
int num;
student *next;
};
student *create()
{
student *head, *p1, *p2;
p1 = (student *)malloc(sizeof(student));
p2 = (student *)malloc(sizeof(student));
int iVal = 0;
head = p1;
scanf("%d", &iVal);
while(iVal)
{
++n;
p1->num = iVal;
scanf("%d", &iVal);
if (iVal)
{
p1->next = p2;
p1 = p2;
p2 = (student *)malloc(sizeof(student));
}
};
p1->next = NULL;
return head;
}
void print(student *head)
{
struct student *p;
printf("there are %d records: \n", n);
p = head;
while(p != NULL)
{
printf("%ld\n",p->num);
p = p->next;
};
}
int main()
{
student *head = create();
print(head);
return 0;
}
#include <stdlib.h>
int n = 0;
struct student
{
int num;
student *next;
};
student *create()
{
student *head, *p1, *p2;
p1 = (student *)malloc(sizeof(student));
p2 = (student *)malloc(sizeof(student));
int iVal = 0;
head = p1;
scanf("%d", &iVal);
while(iVal)
{
++n;
p1->num = iVal;
scanf("%d", &iVal);
if (iVal)
{
p1->next = p2;
p1 = p2;
p2 = (student *)malloc(sizeof(student));
}
};
p1->next = NULL;
return head;
}
void print(student *head)
{
struct student *p;
printf("there are %d records: \n", n);
p = head;
while(p != NULL)
{
printf("%ld\n",p->num);
p = p->next;
};
}
int main()
{
student *head = create();
print(head);
return 0;
}