关于学生管理系统的,帮忙看看,本人菜鸟一个

renbin5566 2010-05-11 07:06:44
# include <stdio.h>
# include <stdlib.h>
# include "ctype.h"
# include "conio.h"
# include "io.h"
# include "windows.h"
# include "ctype.h"
# include "string.h"
# define N 50
static n=0;
struct stuinfo{//定义结构体
char name[20];
long num;
char sex;
float scor;
}stu[N],*student;
void goxy(int x,int y)//光标定位
{
HANDLE hcon;
hcon=GetStdHandle(STD_OUTPUT_HANDLE);
COORD seps;
seps.X=x;
seps.Y=y;
SetConsoleCursorPosition(hcon,seps);
}
void frame(int x,int y,int wideth,int higth)//边框函数
{
for(int i=0;i<higth;i++)
for(int j=0;j<wideth*2;j+=2)
{
goxy(x+j,y+i);
if(j==0||j==wideth*2-2||i==0||i==higth-1){
if(i==0&&j==0)
printf("┏");
else if(i==0&&j==wideth*2-2)
printf("┓");
else if(i==higth-1&&j==0)
printf("┗");
else if(i==higth-1&&j==wideth*2-2)
printf("┛");
else if(i==0||i==higth-1)
printf("━");
else
printf("┃");
}
}
}
void menus()//菜单函数
{
system("cls");
goxy(30,5);
puts("学生信息管理系统");
puts("\t\t\t---------------------------");
puts("\t\t\t\t功 能 菜 单");
puts("\t\t\t---------------------------");
puts("\t\t 1. 输入学生数据\t 2.查看学生数据");
frame(10,3,30,18);
}

void newdata()//建立一个学生信息
{
system("cls");
printf("please input the %d strdents's datas(name,num,sex,scor)\n",n+1);
printf("input name:");
scanf("%s",stu[n].name);
getchar();

printf("input number:");
scanf("%ld",&stu[n].num);
getchar();

printf("input sex:");
scanf("%c",&stu[n].sex);
getchar();

printf("input score:");
scanf("%f",&stu[n].scor);
getchar();
n++;
}
void savemessage()//输入学生的信息,并保存到文件
{
do{
FILE *fp;
fp=fopen("message.txt","at+");
if(fp==NULL){
printf("打开文件失败");
exit(0);
}
newdata();
fwrite(&stu[n],sizeof(stu[n]),1,fp);
puts("\n\t\t按任意键继续,@键结束输入");
}while(getch()!='@');
}
void output(struct stuinfo *s)//输出
{
printf("%-12s\t %-8ld\t %c\t %6.2f\n",s->name,s->num,s->sex,s->scor);

}
void list()//列出学生信息
{
FILE *fp;
fp=fopen("message.txt","rb");
for(int i=0;i<n;i++)
{
fread(&stu[n],sizeof(*student),1,fp);
printf("%-12s\t %-8ld\t %c\t %6.2f\n",stu[n].name,stu[n].num,stu[n].sex,stu[n].scor);
}
}
void choic()
{
menus();
char c;
goxy(25,18);
printf("请输入你的选择(1~2):");
c=getchar();
switch(c)
{
case '1':
savemessage();
menus();
break;
case '2':
list();
menus();
break;
default:;
}
}

void main()//主函数
{
system("cls");
printf("\n\n\n%25c欢迎使用学生信息管理系统",32);
Sleep(500);
system("cls");
choic();
}

运行部了,编译没错 望不妥之处 多多指教
...全文
111 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
renbin5566 2010-05-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jiuchang 的回复:]
运行不了是什么意思,界面不出来?没有结果?还是结果不正确
[/Quote]# include <stdio.h>
# include <stdlib.h>
# include "ctype.h"
# include "conio.h"
# include "io.h"
# include "windows.h"
# include "ctype.h"
# include "string.h"
# define N 50
static n=0;
struct stuinfo{//定义结构体
char name[20];
long num;
char sex;
float scor;
}stu[N],*student;
void goxy(int x,int y)//光标定位
{
HANDLE hcon;
hcon=GetStdHandle(STD_OUTPUT_HANDLE);
COORD seps;
seps.X=x;
seps.Y=y;
SetConsoleCursorPosition(hcon,seps);
}
void frame(int x,int y,int wideth,int higth)//边框函数
{
for(int i=0;i<higth;i++)
for(int j=0;j<wideth*2;j+=2)
{
goxy(x+j,y+i);
if(j==0||j==wideth*2-2||i==0||i==higth-1){
if(i==0&&j==0)
printf("┏");
else if(i==0&&j==wideth*2-2)
printf("┓");
else if(i==higth-1&&j==0)
printf("┗");
else if(i==higth-1&&j==wideth*2-2)
printf("┛");
else if(i==0||i==higth-1)
printf("━");
else
printf("┃");
}
}
}
void menus()//菜单函数
{
system("cls");
goxy(30,5);
puts("学生信息管理系统");
puts("\t\t\t---------------------------");
puts("\t\t\t\t功 能 菜 单");
puts("\t\t\t---------------------------");
puts("\t\t 1. 输入学生数据\t 2.查看学生数据");
frame(10,3,30,18);
}

void newdata()//建立一个学生信息
{
system("cls");
printf("please input the %d strdents's datas(name,num,sex,scor)\n",n+1);
printf("input name:");
scanf("%s",stu[n].name);
getchar();

printf("input number:");
scanf("%ld",&stu[n].num);
getchar();

printf("input sex:");
scanf("%c",&stu[n].sex);
getchar();

printf("input score:");
scanf("%f",&stu[n].scor);
getchar();
n++;
}
void savemessage()//输入学生的信息,并保存到文件
{
do{
FILE *fp;
fp=fopen("message","wb");
if(fp==NULL){
printf("打开文件失败");
exit(0);
}
newdata();
fwrite(&stu[n],sizeof(stu[n]),1,fp);
puts("\n\t\t按任意键继续,@键结束输入");
}while(getch()!='@');
}
/*void output(struct stuinfo *s)//输出
{
printf("%-12s\t %-8ld\t %c\t %6.2f\n",s->name,s->num,s->sex,s->scor);

}*/
void list()//列出学生信息
{
system("cls");
FILE *fp;
fp=fopen("message","rb");
printf("姓名\t 学号\t\t性别\t 分数\n");
for(int i=0;i<n;i++)
{
fread(&stu[n],sizeof(*student),1,fp);
printf("%-12s\t %-8ld\t %c\t %6.2f\n",stu[i].name,stu[i].num,stu[i].sex,stu[i].scor);

}
getch();
}
void choic()
{
menus();
char c;
goxy(25,18);
printf("请输入你的选择(1~2):");
c=getchar();
switch(c)
{
case '1':
savemessage();
choic();
break;
case '2':
list();
choic();
break;
default:;
}
}

void main()
{
system("cls");
printf("\n\n\n%25c欢迎使用学生信息管理系统",32);
Sleep(500);
system("cls");
choic();
}

我想把记录写入到文件中,可是写入不成功,文件是空我不知道哪里错了
renbin5566 2010-05-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jiuchang 的回复:]
运行不了是什么意思,界面不出来?没有结果?还是结果不正确
[/Quote]
结果出不来,不知道哪里错了
匚匚 2010-05-11
  • 打赏
  • 举报
回复
LZ可以到这里去看一下,相信你会收获不小
http://blog.csdn.net/zhw952/archive/2010/05/02/5550803.aspx
jiuchang 2010-05-11
  • 打赏
  • 举报
回复
运行不了是什么意思,界面不出来?没有结果?还是结果不正确

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧