编一个C语言程序,输入学生的学号和姓名(有指针和SWITCH)。有4个CASE。一是增加学生信息,

2是删除学生信息,3是显示输入的学生信息,4是退出(可以使按0退出)。
谢谢!

程序是以前写的,里面的指针有些可能有些冗余,但是应该是可以执行的
主程序里面的菜单刚才写的,但是没有编译器所以不能帮你调试,不过应该不会有什么大问题
呵呵,希望有用
#include "stdio.h"
#include "stdlib.h"
#include "malloc.h"
#define NULL 0
#define LEN sizeof(struct student)

struct student
{
long num;
float score;
struct student *next;
};

int n;
struct student *creat(void)
{
struct student *p1,*p2,*head;
n=0;
p1=p2=(struct student*) malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)
head=p1;
else
p2=p1;

p1=(struct student*) malloc(LEN);
p2->next = p1;
scanf("%ld,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}

void print(struct student *head)
{
struct student *p;
printf("\nNow,These %d records are:\n",n);
p=head;
if(head!=NULL)
while(p!=NULL)
{
printf("%ld,%5.1f\n",p->num,p->score);
p=p->next;
}
}

struct student *del(struct student *head,long num)
{
struct student *p1,*p2;

if(head==NULL)
{
printf("\nlist null!\n");
return(head);
}
p1=head;

while(num!=p1->num && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}

if(num==p1->num)
{
if(num==head->num)
head=p1->next;
else
p2->next=p1->next;
printf("delete:%ld\n",num);
n=n-1;
}
else
printf("%ld not been found!\n",num);
return(head);
}

struct student *insert(struct student *head,struct student *stu)
{
struct student *p1,*p2,*p0;
p1=head;p0=stu;
if(head==NULL)
{head=p0;head->next=NULL;}

while((p0->num>p1->num) && (p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}

if(p0->num<=p1->num)
{
if(p1==head)
{
head=p0;
p0->next=p1;
}
else
{
p2->next=p0;
p0->next=p1;
}
}
else
{
p1->next=p0;
p0->next=NULL;
}

n=n+1;
return(head);
}

int main(void)
{
struct student *head,*stu;
long del_num;
int chos=0;
while(chos != 5)
{
printf("菜单1:创建\t2:显示\t3:删除\t4:插入\t5:退出");
scanf("%d", &chos);

switch(chos)
case 1:
printf("please input records:\n");
head=creat();
break;
case 2:
print(head);
break;
case 3:
printf("\nplease input the deleted number:\n");
scanf("%ld",&del_num);
while(del_num!=0)
{
head=del(head,del_num);
print(head);
printf("\nplease input the deleted number:\n");
scanf("%ld",&del_num);
}
break;
case 4:
printf("\nplease input the insert records:\n");
stu=(struct student*)malloc(LEN);
scanf("%ld,%f",&stu->num,&stu->score);
while(stu->num!=NULL)
{
head=insert(head,stu);
print(head);
printf("\nplease input the insert records:\n");
stu=(struct student*)malloc(LEN);
scanf("%ld,%f",&stu->num,&stu->score);
}
break;
case 5:
exit(0);
default:
continue;
}

return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-01-08
#include<stdio.h>
struct person
{
char name;
int age;
char sex;
float height;
}per={"Li Hua",20,'M',175.5}
main()
{

}