You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
4.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<ctype.h>
#define Esc 27
#define LEN sizeof(struct student)
struct student
{ char num[20]; // 学号
char name[20]; // 姓名
int age; // 年龄
char sex[7]; // 性别
char birthday[20]; // 出生日期
char address[100]; // 地址
char phone[15]; // 电话
char email[30]; // 邮箱
struct student *next;
}stu;
void welcome(); //欢迎界面
void First(); //功能1学生信息录入
void Second(struct student *head); //功能2学生信息浏览
void Third(); //功能3 查询,排序
void Fourth(); //功能4 删除,修改
void exit(); //退出界面
void goon();
int main()
{ int n=0;
char chose='a';
do
{ system("cls");
welcome();
chose=getch();
if(chose=='1')
{ system("cls");
First();
n=1;
goon();
}
else if((n==0)&&(chose!=Esc))
{
printf("\n\t错误:你必须先输入学生信息!!!");
goon();
}
else if(chose=='2'&&n==1)
{ system("cls");
}
else if(chose=='3')
{
}
else if(chose=='4')
{
}
}
while(chose!=Esc);
exit();
}
void welcome()
{
printf(" 欢迎进入 \n");
printf("******************学生信息管理系统菜单******************\n");
printf(" 1.学生信息录入 \n");
printf(" 2.学生信息浏览 \n");
printf(" 3.查询,排序 \n");
printf(" 4.学生信息的删除与修改 \n");
printf(" Esc.退出系统 \n");
printf("--------------------------------------------------------\n");
printf("********************************************************\n");
printf(" 请输入所需功能的序号!!! \n");
}
void First()
{ int i=1;
char ch;
FILE *fp;
if((fp=fopen("a.txt","ab+"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
do
{
printf("\n\n\t请输入学生的信息: \n");
printf("\t输入格式为:(每输入一项回车)\n");
printf("学号:");
scanf("%s",stu.num);
printf("\n");
printf("姓名:");
scanf("%s",stu.name);
printf("\n");
printf("年龄:");
scanf("%d",&stu.age);
printf("\n");
do
{
printf("性别(man/woman):");
scanf("%s",stu.sex);
if((strcmp(stu.sex,"man"))&&(strcmp(stu.sex,"woman")))
{
printf("输入有误,请按正确格式输入!\n");
continue;
}
i=0;
}while(i);
printf("\n");
printf("出生日期(####/##/##):");
scanf("%s",stu.birthday);
printf("\n");
printf("地址:");
scanf("%s",stu.address);
printf("\n");
printf("电话:");
scanf("%s",stu.phone);
printf("\n");
printf("邮箱:");
scanf("%s",stu.email);
if(fwrite(&stu,LEN,1,fp)!=1)
{
printf("file write error\n");
exit(0);
}
printf("是否继续录入?(y/n)\n");
getchar();
ch=getchar();
}
while(ch=='y');
if(fclose(fp))
{
printf("can not close the file!\n");
exit(0);
}
}
void Second(struct student *head)
{ char num[20]; // 学号
char name[20]; // 姓名
int age; // 年龄
char sex[7]; // 性别
char birthday[20]; // 出生日期
char address[100]; // 地址
char phone[15]; // 电话
char email[30]; // 邮箱
FILE *fp;
if((fp=fopen("a.txt","ab+"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
fread(head,LEN,1,fp);
printf("%s",head->num);
}
void Third()
{
}
void Fourth()
{
}
void goon()
{
printf("按任意键继续!!!");
getch();
}
void exit()
{ system("cls");
printf(" ");
printf("**************************************************************\n");
printf(" ");
printf("*****************谢谢使用学生信息管理系统*********************\n");
printf(" ");
printf("**************************************************************\n");
printf(" ");
printf("================您的使用是对我们工作最大的认可=================");
}