关于c语言编程问题!请帮忙找找错误,谢谢了!请在改动处做标记。
3个回答
展开全部
程序本身没有任何语法错误,最多个把警告,程序本身也能完全运行。不知道lz要别人帮你找什么错误?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/************************************************************************************************************/
/******************************************学生简历管理系统.CPP**********************************************/
/****************************************************2009.9.9************************************************/
/************************************************************************************************************/
#include<stdio.h>
#include<malloc.h>
#define
LENGTH
sizeof(struct
student)
#include
<stdlib.h>
#include
<string.h>
struct
student
{
long
num;
int
clas;
//用四位数表示clas,例如0801
char
name[20];
char
sex[6];
//用male与female表示
float
score;
struct
student
*next;
};
int
n;struct
student
*head,*stud;long
del_num=0;char
xname[20];int
xnum=0;int
flag=1;
struct
student
*creat(void)
//创建动态链表
{
struct
student
*p1,*p2;
n=0;
p1=p2=(struct
student
*)malloc(LENGTH);
printf("请输入学号,如05:");
scanf("%ld",&p1->num);
printf("请输入班级,如01:");
scanf("%d",&p1->clas);
printf("请输入姓名:");
scanf("%s",p1->name);
printf("请选择性别(female,male):");
scanf("%s",p1->sex);
printf("请输入分数:");
scanf("%f",&p1->score);
head=NULL;
while(flag!=0)
{
n=n+1;
if(n==1)
head=p1;
else
{
p2->next=p1;
p2=p1;
}
p1=(struct
student
*)malloc(LENGTH);
printf("请输入学号,如05:");
scanf("%ld",&p1->num);
printf("请输入班级,如01:");
scanf("%d",&p1->clas);
printf("请输入姓名:");
scanf("%s",p1->name);
printf("请选择性别(female,male):");
scanf("%s",p1->sex);
printf("请输入分数:");
scanf("%f",&p1->score);
printf("结束学生信息输入请输入0,否则输入1:");
scanf("%d",&flag);
}
p2->next=NULL;
return(head);
}
void
findname(struct
student
*head,char
xname[20])
//按姓名查找
{
int
mark=0;
while(head!=NULL)
{
if(head->name==xname)
{
printf("\n%ld,%d,%s,%s,%f",head->num,head->clas,head->name,head->sex,head->score);
mark=1;
break;
}
else
head=head->next;
}
if(mark==0)
printf("未发现!");
}
void
findID(struct
student
*head,int
xnum)
//按学号查找
{
int
mark=0;
while(head!=NULL)/*此处改动*/
{
if(head->num==xnum)
{
printf("\n%ld,%d,%s,%s,%f",head->num,head->clas,head->name,head->sex,head->score);
mark=1;
break;
}
else
head=head->next;
}
if(mark==0)
printf("未发现!");
}
struct
student
*del(struct
student
*head,long
del_num)
//记录的删除
{
struct
student
*p1,*p2;
if(head==NULL)
{
printf("\nlist
null!\n");
goto
end;
}
else
{
p1=head;
while(del_num=!p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(del_num==p1->num)
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
printf("delete:%d\n",del_num);
n=n-1;
}
else
printf("%d
not
been
found!\n",del_num);
}
end:return(head);
}
struct
student
*insert(struct
student
*head,struct
student
*stud)
//stud为待插入节点,按学号大小排序插入的记录
{
struct
student
*p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->num<=p1->num)
{
if(head==p1)
head=p0;
else
{
p2->next=p0;
p0->next=p1;
p0->next=p1;
}
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
n=n+1;
return(head);
}
void
print(struct
student
*head)
//记录的输出读取
{
struct
student
*p;
p=head;
printf("\nNow,these
records
are:\n");
if(head!=NULL)
do
{
printf("学号:%ld\n",p->num);
printf("班级:%d\n",p->clas);
printf("姓名:%s\n",p->name);
printf("性别:%s\n",p->sex);
printf("分数:%f\n",p->score);
p=p->next;
}
while(p!=NULL);
}
/*show*/
int
main()/*此处改动*/
{
int
choice=0;
printf("输入学生信息:\n");
head=creat(
);
print(head);
printf("\n1:分班显示记录\n");
printf("2:按姓名查找记录\n");
printf("3:按学号查找记录\n");
printf("4:删除记录\n");
printf("5:记录排序\n");
printf("6:退出\n");
do
{
printf("请输入功能选择:");
scanf("%d",&choice);
if(choice==1)
{
}
else
if(choice==2)
{
printf("请输入要查找的学生姓名:");
scanf("%s",xname);
findname(head,xname);
}
else
if(choice==3)
{
printf("请输入要查找的学生学号:");
scanf("%d",&xnum);
findID(head,xnum);
}
else
if(choice==4)
{
printf("请输入要删除的学生学号:");
scanf("%d",&del_num);
struct
student
*del(struct
student
*head,long
del_num);
}
else
if(choice==5)
{
printf("请输入要插入的节点:num、clas、name、sex、score\n");
scanf("%ld,%d,%s,%s,%f",&stud->num,&stud->clas,stud->name,stud->sex,&stud->score);
struct
student
*insert(struct
student
*head,struct
student
*stud);
}
else
if(choice==6)
{
printf("谢谢使用!\n");
}
else
printf("非法输入,请输入1~6之间的数!\n");
}
while(choice!=6);
}
/******************************************学生简历管理系统.CPP**********************************************/
/****************************************************2009.9.9************************************************/
/************************************************************************************************************/
#include<stdio.h>
#include<malloc.h>
#define
LENGTH
sizeof(struct
student)
#include
<stdlib.h>
#include
<string.h>
struct
student
{
long
num;
int
clas;
//用四位数表示clas,例如0801
char
name[20];
char
sex[6];
//用male与female表示
float
score;
struct
student
*next;
};
int
n;struct
student
*head,*stud;long
del_num=0;char
xname[20];int
xnum=0;int
flag=1;
struct
student
*creat(void)
//创建动态链表
{
struct
student
*p1,*p2;
n=0;
p1=p2=(struct
student
*)malloc(LENGTH);
printf("请输入学号,如05:");
scanf("%ld",&p1->num);
printf("请输入班级,如01:");
scanf("%d",&p1->clas);
printf("请输入姓名:");
scanf("%s",p1->name);
printf("请选择性别(female,male):");
scanf("%s",p1->sex);
printf("请输入分数:");
scanf("%f",&p1->score);
head=NULL;
while(flag!=0)
{
n=n+1;
if(n==1)
head=p1;
else
{
p2->next=p1;
p2=p1;
}
p1=(struct
student
*)malloc(LENGTH);
printf("请输入学号,如05:");
scanf("%ld",&p1->num);
printf("请输入班级,如01:");
scanf("%d",&p1->clas);
printf("请输入姓名:");
scanf("%s",p1->name);
printf("请选择性别(female,male):");
scanf("%s",p1->sex);
printf("请输入分数:");
scanf("%f",&p1->score);
printf("结束学生信息输入请输入0,否则输入1:");
scanf("%d",&flag);
}
p2->next=NULL;
return(head);
}
void
findname(struct
student
*head,char
xname[20])
//按姓名查找
{
int
mark=0;
while(head!=NULL)
{
if(head->name==xname)
{
printf("\n%ld,%d,%s,%s,%f",head->num,head->clas,head->name,head->sex,head->score);
mark=1;
break;
}
else
head=head->next;
}
if(mark==0)
printf("未发现!");
}
void
findID(struct
student
*head,int
xnum)
//按学号查找
{
int
mark=0;
while(head!=NULL)/*此处改动*/
{
if(head->num==xnum)
{
printf("\n%ld,%d,%s,%s,%f",head->num,head->clas,head->name,head->sex,head->score);
mark=1;
break;
}
else
head=head->next;
}
if(mark==0)
printf("未发现!");
}
struct
student
*del(struct
student
*head,long
del_num)
//记录的删除
{
struct
student
*p1,*p2;
if(head==NULL)
{
printf("\nlist
null!\n");
goto
end;
}
else
{
p1=head;
while(del_num=!p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(del_num==p1->num)
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
printf("delete:%d\n",del_num);
n=n-1;
}
else
printf("%d
not
been
found!\n",del_num);
}
end:return(head);
}
struct
student
*insert(struct
student
*head,struct
student
*stud)
//stud为待插入节点,按学号大小排序插入的记录
{
struct
student
*p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->num<=p1->num)
{
if(head==p1)
head=p0;
else
{
p2->next=p0;
p0->next=p1;
p0->next=p1;
}
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
n=n+1;
return(head);
}
void
print(struct
student
*head)
//记录的输出读取
{
struct
student
*p;
p=head;
printf("\nNow,these
records
are:\n");
if(head!=NULL)
do
{
printf("学号:%ld\n",p->num);
printf("班级:%d\n",p->clas);
printf("姓名:%s\n",p->name);
printf("性别:%s\n",p->sex);
printf("分数:%f\n",p->score);
p=p->next;
}
while(p!=NULL);
}
/*show*/
int
main()/*此处改动*/
{
int
choice=0;
printf("输入学生信息:\n");
head=creat(
);
print(head);
printf("\n1:分班显示记录\n");
printf("2:按姓名查找记录\n");
printf("3:按学号查找记录\n");
printf("4:删除记录\n");
printf("5:记录排序\n");
printf("6:退出\n");
do
{
printf("请输入功能选择:");
scanf("%d",&choice);
if(choice==1)
{
}
else
if(choice==2)
{
printf("请输入要查找的学生姓名:");
scanf("%s",xname);
findname(head,xname);
}
else
if(choice==3)
{
printf("请输入要查找的学生学号:");
scanf("%d",&xnum);
findID(head,xnum);
}
else
if(choice==4)
{
printf("请输入要删除的学生学号:");
scanf("%d",&del_num);
struct
student
*del(struct
student
*head,long
del_num);
}
else
if(choice==5)
{
printf("请输入要插入的节点:num、clas、name、sex、score\n");
scanf("%ld,%d,%s,%s,%f",&stud->num,&stud->clas,stud->name,stud->sex,&stud->score);
struct
student
*insert(struct
student
*head,struct
student
*stud);
}
else
if(choice==6)
{
printf("谢谢使用!\n");
}
else
printf("非法输入,请输入1~6之间的数!\n");
}
while(choice!=6);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
奇怪,怎么老报这个:您的回答已被之前网友使用,请重新编辑!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询