#include <stdio.h>
#include <malloc.h>
#include <string.h>
struct student {
int num;
char name[20];
char six[10];
int age;
struct student * next;
};
int n=0;
int main () {
struct student * creat();
struct student * cp(struct student *);
struct student *head;
void print(struct student *);
head=creat();
head=cp(head);
print(head);
return 0;
}
struct student * creat(){
struct student *p1,*p2,*head;
p1=p2=(struct student *)malloc(sizeof(struct student));
printf("input number & score of studnet:");
scanf("%d %s %s %d",&p1->num,p1->name,p1->six,&p1->age);
head=NULL;
while(p1->num!=0){
n=n+1;
if(n==1){
head=p1;
}
else{
p2->next=p1;
}
p2=p1;
p1=(struct student *)malloc(sizeof(struct student));
printf("input number & score of student:");
scanf("%d %s %s %d",&p1->num,p1->name,p1->six,&p1->age);
}
p2->next=NULL;
return head;
}
void print(struct student * head){
struct student *p;
p=head;
printf("There are %d records:\n",n);
do{
printf("%d %s %s %d\n",p->num,p->name,p->six,p->age);
p=p->next;
}while(p!=NULL);
}
struct student *cp(struct student *head){
struct student *p1,*p2;
int target,i=0;
p1=p2=head;
scanf("%d",&target);
while(p1->num!=target&&p1->next!=NULL){
i=i+1;
if(i==1){
p1=p1->next;
}else{
p2=p1;
p1=p1->next;
}
}
if(i==0){
head=p1->next;
}else if(p1->num==target){
p2->next=p1->next;
}else{
printf("error\n");
}
return head;
}