作为新手 课程设计刚写到 输入 发现实际输入与输入的值不同 (birthday与score)
#include <stdio.h>
#include <stdlib.h>
#include<malloc.h>
#include<conio.h>
#include<ctype.h>
#include<mem.h>
#define LEN sizeof(struct student)
struct student *head=NULL;
struct student
{
int num;
char name[20];
char specialty[20];
int birthday[20];
char address[20];
int score[20];
struct student *next;
};
int n;
struct student *creat();
int output(struct student *head);
float Statistic(struct student *p);
struct student *creat()
{
struct student *head;
struct student *pl,*p2;
n=0;
pl=p2=(struct student*) malloc(LEN);
printf("学号:\n");
scanf("\t%d",&pl->num);
printf("姓名:\n");
scanf("\t%s",&pl->name);
printf("专业:\n");
scanf("\t%s",&pl->specialty);
printf("出生日期:\n");
scanf("\t%d",&pl->birthday);
printf("住址:\n");
scanf("\t%s",&pl->address);
printf("成绩:\n");
scanf("\t%d",&pl->score);
printf("\n");
head=NULL;
while(pl->num !=0)
{
n=n+1;
if(n==1)head=pl;
else p2->next=pl;
p2=pl;
//创建链表
pl=(struct student*)malloc(LEN);
printf("\n\t如果你想结束输入,请输入 0 !\n\n");
printf("\t请输入学号:");
scanf("%d",&pl->num );
if(pl->num ==NULL) //控制是否退出
continue;
printf("姓名:\n");
scanf("\t%s",&pl->name);
printf("专业:\n");
scanf("\t%s",&pl->specialty);
printf("出生日期:\n");
scanf("\t%d",&pl->birthday);
printf("住址:\n");
scanf("\t%s",&pl->address);
printf("成绩:\n");
scanf("\t%d",&pl->score);
printf("\n");
}
p2->next=NULL;
return (head);
}
//输出链表
int output(struct student *head)
{
struct student *p;
printf("\n\t现在有%d个记录是:\n",n);
p=head;
if(head!=NULL)
do
{
printf("学号 : %d\n",p->num);
printf("姓名 : %s\n",p->name);
printf("专业 :%s\n",p->specialty);
printf("生日 : %s\n",p->birthday);
printf("住址 : %s\n",p->address);
printf("成绩 : %s\n",p->score);
p=p->next ;
} while(p!=NULL);
return 1;
}
int main()
{
menu();
return 0;
}
int menu()//目录
{
printf("\n");
printf("\n");
printf(" *****************学生信息管理****************\n");
printf(" 1.新增学生信息 \n");
printf(" 2.修改学生信息 \n");
printf(" 3.删除学生信息 \n");
printf(" 4.学生信息搜索 \n");
printf(" 5.学生信息统计 \n");
printf(" 6.成绩排序(英语) \n");
printf(" 7.保存学生信息 \n");
printf(" 8.退出 \n");
printf(" *********************************************\n");
list();
return 0;
}
int list()//选择函数
{
int n,flag;
char a;
do
{
printf("选择您需要操作的步骤1-7:\n");
scanf("%d",&n);
if(n>=1&&n<=8)
{
flag=1;
break;
}
else
{
flag=0;
printf("输入错误 请重新选择。\n");
}
}while(flag==0);
while(flag==1)
{
switch(n)
{
case 1:
printf("*****************新增学生信息****************\n");
printf("\n");
head=creat();
output(head);
printf("输入完毕\n");
break;
case 2:
printf("*****************修改学生信息****************\n");
printf("\n");
printf("录入完毕\n");
break;
case 3:
printf("*****************删除学生信息****************\n");
printf("\n");
printf("删除完毕\n");
break;
case 4:
printf("*****************学生信息搜索****************\n");
printf("\n");
break;
case 5:
printf("*****************学生信息统计****************\n");
printf("\n");
break;
case 6:
printf("*****************成绩排序(英语)****************\n");
printf("\n");
break;
case 7:
printf("*****************保存学生信息****************\n");
printf("\n");
printf("保存完毕\n");
break;
case 8:
exit(0);
break;
}
printf("\n");
printf("返回主菜单(y or n):\n");
getchar();
scanf("%c",&a);
if(a=='y')
{
flag=1;
system("cls");//清屏函数
menu();
printf("选择您需要操作的步骤1-7:\n");
scanf("%d",&n);
printf("\n");
}
else
exit(0);//结束程序
}
return 0;
}