|
发表于 2013-9-2 21:20:55
|
显示全部楼层
修改后的截图和代码。。。
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- typedef struct Student
- {
- int grade;
- char name[4];
- struct Student * next;
- }Nodestud;
- Nodestud* ctreate()
- {
- Nodestud*head,*p,*q;
- head=NULL;
-
- printf(" **** 请输入学生的信息:*****\n\n");
- while(1)
- {
- p=(Nodestud*)malloc(sizeof(Nodestud));
- printf("请输入学生的姓名:");
- scanf("%s",p->name);
- if(strcmp(p->name,"#")==0)
- {
- p->next=NULL;
- return head;
- //break;
- }
- printf("请输入学生的成绩:");
- scanf("%d",&(p->grade));
- if(head==NULL)
- {
- head=p;
- q=head;
- }
- else
- {
- q->next=p;
- q=p;
- }
- }
-
- }
- void DeleStud(Nodestud*head)
- {
- char nam[5];
- Nodestud*p,*q=head;
- printf("请输入要删除学生的姓名:\n");
- scanf("%s",nam);
- if(strcmp(q->name,nam)==0)
- { head=q->next;
- free(q);
-
- }
- while(q)
- {
- if(strcmp(q->next->name,nam)==0)
- {
- p=q->next;
- q->next=p->next;
- free(p);
- p=NULL;
- break;
- }
- }
- }
- void Deststud(Nodestud*head)
- {
- Nodestud*p=head;
- while(p)
- {
- head=p->next;
- free(p);
- p=head;
- }
- printf("删除成功!\n");
- }
- void main()
- {
- int chose;
- Nodestud *stud;
- start: printf("***** 1: 创建学生信息 *****\n");
- printf("***** 2: 删除某位学生信息*****\n");
- printf("***** 3: 销毁学生信息 *****\n");
- printf("***** 0: 退出*** *****\n");
- scanf("%d",&chose);
- switch(chose)
- {
- case 1: stud=ctreate(); break;
- case 2: DeleStud(stud);break;
- case 3: Deststud(stud);break;
- case 0: exit(0);
- }
- goto start;
-
- }
复制代码 |
|