#include
#include
#include
#include
struct student
{
char name[20];
char sex[5];
char num[100];
int age;
int high;
int weight;
}stu;
void input(struct student *p)
{
FILE *fp;
fp=fopen("information.dat","wb");
printf("请输入学生的信息:\n");
printf("在姓名处输入-1表示结束\n");
while(1)
{
printf("姓名:");
scanf("%s",p->name);
if(!strcmp(p->name,"-1"))
break;
printf("性别:");
scanf("%s",p->sex);
printf("学号:");
scanf("%s",p->num);
printf("年纪:");
scanf("%d",&stu.age);
printf("身高:");
scanf("%d",&stu.high);
printf("体重:");
scanf("%d",&stu.weight);
fwrite(p,sizeof(struct student),1,fp);
}
fclose(fp);
printf("输入完成!");
system("pause");
system("cls");
}
void output1(struct student *p)
{
FILE *fp1,*fp2; char name1[20];
fp1=fopen("information.dat","rb+");
fp2=fopen("temp","wb+");
printf("请输入学生姓名:\n");
scanf("%s",name1);
while(1)
{
fread(p,sizeof(struct student),1,fp1);
if(!strcmp(p->name,name1))
{
fwrite(p,sizeof(struct student),1,fp2);
}
break;
}
fclose(fp1);
fclose(fp2);
remove("information.dat");
rename("temp","information.dat");
fp1=fopen("information.dat","rb");
fread(p,sizeof(struct student),1,fp1);
printf("姓名:%s\n",p->name);
printf("性别:%s\n",p->sex);
printf("学号:%s\n",p->num);
printf("年纪:%d\n",stu.age);
printf("身高:%d\n",stu.high);
printf("体重:%d\n",stu.weight);
fclose(fp1);
system("pause");
system("cls");
}
void output2(struct student *p)
{
FILE *fp;
if ((fp=fopen("information.dat","rb")) == NULL)
{
printf ("文件打开失败!\n");
exit (0);
}
fread(p,sizeof(struct student),1,fp);
while(!feof(fp))
{
printf("姓名:%s\n",p->name);
printf("性别:%s\n",p->sex);
printf("学号:%s\n",p->num);
printf("年纪:%d\n",stu.age);
printf("身高:%d\n",stu.high);
printf("体重:%d\n",stu.weight);
fread(p,sizeof(struct student),1,fp);
}
fclose(fp); system("pause");
system("cls");
}
void end()
{
exit(0);
}
void main()
{
struct student *a=&stu;
int chose;
while(1)
{
printf("\t\t\t\n");
printf("\t\t\t请输入正确的选择:\n");
printf("\t\t\t1.全部输入\n");
printf("\t\t\t2.按照姓名查找\n");
printf("\t\t\t3.全部输出\n");
printf("\t\t\t4.退出\n");
printf("\t\t\t请输入选择:");
scanf("%d",&chose);
switch(chose)
{
case 1:input(a);
break;
case 2:output1(a);
break;
case 3:output2(a);
break;
case 4:end();
}
}
}
我有写过一个学生管理系统的代码,说真的要写好还不是特别容易;我只是说事,不是来给代码的,我写的不咋样。还有就是看你的要求多高。要求不高的话,你自己动手肯定可以写;要求高的话,那你可得花点心思了。话说随便一套完整的代码都是一种汗水去换来的,要么比别人努力;要么就去网上淘,明白点就是花钱。
10财富值就想要个完整的,特么是穷疯了吧,思路都不告诉你
这个我可以做,课程设计