07/11/25 09:50:24
>>5
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct grade
{
char name[40];
int score;
struct grade *next;
} glist;
glist *cons(glist car, glist *cdr)
{
glist *l;
if( (l = malloc(sizeof(glist))) == NULL ) exit( EXIT_FAILURE );
sprintf(l->name, car.name);
l->score = car.score;
l->next = cdr;
return l;
}
void printList(glist *ptr)
{
if(ptr == NULL) return;
printf("p->name \t%s\n", ptr->name);
printf("p->score\t%d\n", ptr->score);
printf("p->next \t%p\n", ptr->next);
printList(ptr->next);
return;
}