-sharpinclude<stdio.h>
-sharpinclude<stdlib.h>
struct student {
int num;//
struct student *next;//
};
struct student *crea(int n)
{
struct student *head, *pa, *pb;
int i;
head = NULL;
for (i = 0; i < n; iPP)
{
pb = (struct student*)malloc(sizeof(struct student));
if (pb == NULL)
{
printf("%d!", i + 1);
break;
}
}
printf(":");
pb = head;
scanf_s("%d", &pb->num);
if (i == 0)
{
head = pb;
pa = pb;
}
return head;
}
void print(struct student *head)
{
struct student *p = head;
while(p != NULL)
{
printf(":%d", p->num);
p = p->next;
}
}
int main()
{
struct student *head = crea(1);
print(head);
system("pause");
return 0;
}
photos can"t always be uploaded. I don"t know why.
hints that the local pointer variable pb, which may not be initialized, is used