69,382
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
int n;
struct student
{long num;
float score;
struct student *next;
};
void main()
{
struct student *p;
struct student *cre(struct student *p);
// struct student *ins(void);
// struct student *del(void);
// void pri(struct student *p);
void pra(struct student *p);
int d;
n=0;
p=NULL;
do
{
printf("please enter 0\\1\\2\\3\\4\\5:");
scanf("%d",&d);
switch(d)
{
case 1 : p=cre(p);break;
// case 2 : p=ins();break;
// case 3 : p=del();break;
// case 4 : pri(p);break;
case 5 : pra(p);break;
}
}while(d!=0);
printf("\nEND!!\n");
}
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
extern n;
struct student
{long num; float score; struct student *next;};
struct student *cre(struct student *p)
{
struct student *head,*p1,*p2;
head=p;
p1=(struct student *)malloc(LEN);
if (p1!=NULL)
{
n=n+1;
printf("enter the num and score:");
scanf("%ld,%f",p1->num,p1->score);
if (head!=NULL)
{
p2=p+n-1;
p2->next =p1;
p2=p1;
p2->next=NULL;
printf("\n OK!! \n");
}
else
{
head=p1;
p2=p1;
p2->next =NULL;
printf("\n OK!! \n");
}
}
else
printf("error!!!\n");
return(head);
}
#include<stdio.h>
extern n;
struct student
{
long num;
float score;
struct student *next;
};
void pra(struct student *p)
{
int i;
printf("\n**********************************\n");
for(i=0;i<n;i++)
printf("%ld,%5.2f",(p+i)->num,(p+i)->score);
printf("\n**********************************\n");
}