第1个回答 2012-03-08
#include"stdio.h"
#define SIZE 5
struct stu
{
char name[10];
int no;
int age;
char add[10];
}stu[SIZE];
void readdat();
void writedat();
void change();
main()
{
char k;
printf(" 欢迎进入学生信息管理系统\n");
printf("\n\n 1.学生信息输入系统 ");
printf(" 2.学生信息查询系统\n");
printf(" 3.学生信息修改系统\n\n\n");
began:
printf("\n\n请输入选项:");
scanf("%d",&k);
switch(k)
{
case 1: writedat(); break;
case 2: readdat(); break;
case 3: change(); break;
default: goto began;
}
goto began;
while(1);
}
void writedat()
{
FILE *fp;
char i;
printf("\n\n请输入学生的姓名、学号、年龄和地址:\n");
for(i=0;i<SIZE;i++)
{
printf("输入%d号学生信息:",i+1);
scanf("%s %d %d %s",stu[i].name,&stu[i].no,&stu[i].age,stu[i].add);
}
if((fp=fopen("E:\\a.dat","wb"))==NULL)
{
printf("Open Error\n");
return;
}
for(i=0;i<SIZE;i++)
{
if(fwrite(&stu[i],sizeof(struct stu),1,fp)!=1)
printf("write error\n");
}
fclose(fp);
}
void readdat()
{
FILE *fp;
int i,k,kk;
jixu:
printf("查询全部请输入0,查询单个请输入1:");
scanf("%d",&k);
if((fp=fopen("E:\\a.dat","rb"))==NULL)
{
printf("Read Error\n");
return;
}
if(k==0)
{
printf("编号 姓名 学号 年龄 地址\n");
for(i=0;i<SIZE;i++)
{
if(fread(&stu[i],sizeof(struct stu),1,fp)!=1)
{
if(!feof(fp))
printf("write error\n");
return;
}
printf("%-5d%-8s%-8d%-5d%s\n",i+1,stu[i].name,stu[i].no,stu[i].age,stu[i].add);
}
}
else if(k==1)
{
printf("请输入学生的编号:");
scanf("%d",&kk);
printf("编号 姓名 学号 年龄 地址\n");
if(fread(&stu[kk-1],sizeof(struct stu),1,fp)!=1)
{
if(!feof(fp))
printf("write error\n");
return;
}
printf("%-5d%-8s%-8d%-5d%s\n",kk,stu[kk-1].name,stu[kk-1].no,stu[kk-1].age,stu[kk-1].add);
}
else
{
printf("输入错误!");
goto jixu;
}
fclose(fp);
}
void change()
{
FILE *fp;
char i,kk;
while(1)
{
printf("请输入修改信息学生的编号(0退出):");
scanf("%d",&kk);
if(kk==0)
return;
printf("编号 姓名 学号 年龄 地址\n");
if((fp=fopen("E:\\a.dat","rb"))==NULL)
{
printf("Read Error\n");
return;
}
for(i=0;i<SIZE;i++)
if(fread(&stu[i],sizeof(struct stu),1,fp)!=1)
{
if(!feof(fp))
printf("write error\n");
return;
}
printf("%-5d%-8s%-8d%-5d%s\n",kk,stu[kk-1].name,stu[kk-1].no,stu[kk-1].age,stu[kk-1].add);
printf("请输入学生的姓名、学号、年龄和地址:\n");
scanf("%s %d %d %s",stu[kk-1].name,&stu[kk-1].no,&stu[kk-1].age,stu[kk-1].add);
if((fp=fopen("E:\\a.dat","wb"))==NULL)
{
printf("Open Error\n");
return;
}
for(i=0;i<SIZE;i++)
{
if(fwrite(&stu[i],sizeof(struct stu),1,fp)!=1)
printf("write error\n");
}
fclose(fp);
}
}
第2个回答 2012-03-08
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define NULL 0
#define LEN sizeof(struct members)
void menu()
{
printf("\n\t\t﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏\n");
printf("\t ︴ ︴\n");
printf("\t ︴\t\t%c 通讯录 %c ︴\n",2,2);
printf("\t ︴ ﹌﹌﹌﹌ ︴\n");
printf("\t ︴ ︷︷︷︷ ︴\n");
printf("\t ︴ 作者:{fateland} ︴\n");
printf("\t ︴ ︸︸︸︸ ︴\n");
printf("\t\t¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n");
printf("\t ︴ ︴\n");
printf("\t ︴\t ︹︹︹︹︹ \t ︹︹︹︹︹ ︴\n");
printf("\t ︴ 1.〔添加联系人〕 2.〔查找联系人〕 ︴\n");//查找中再来一个菜单用以修改信息
printf("\t ︴\t ︺︺︺︺︺ \t ︺︺︺︺︺ ︴\n");
printf("\t ︴ ︴\n");
printf("\t ︴\t ︹︹︹︹︹ \t ︹︹︹︹︹ ︴\n");
printf("\t ︴ 3.〔删除联系人〕 4.〔退出通讯录〕 ︴\n");
printf("\t ︴\t ︺︺︺︺︺ \t ︺︺︺︺︺ ︴\n");
printf("\t ︴ ︴\n");
printf("\t\t¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n");
printf("\t ︴ ︴\n");
printf("\t ︴\t …请选择序号操作…\t ︴\n");
printf("\t ︴ ︴\n");
printf("\t\t﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌\n");
}
struct members
{
char num[20]; //序号
char name[20]; //姓名
char sex[1]; //姓别
int age; //年龄
char tel[12]; //电话
char address[100];//地址
struct members *next;
};
int n;
struct members *add(struct members *head)
{
struct members *p0,*p1,*newmem=NULL;
p0=head;
p1=head;
newmem=(struct members *)malloc(LEN);
printf("\t请输入联系人序号:");
scanf("%s",&p0->num);
printf("%s",p0->num);
return(0);
}
struct members *search(struct members *head)
{
}
struct members *del(struct members *head)
{
}
void over()
{
exit(0);
}
main()
{
int a;
FILE *f1,*f2;
struct members *head=NULL;
if(f1=fopen("Members.lang","ab")==NULL)
{
f2=fopen("Members.lang","wb");
fclose(f2);
}
while(1)
{
menu();
printf("\n\t请选择操作");
scanf("%d",&a);
switch(a)
{
case 1:head=add(head);break;
case 2:head=search(head);break;
case 3:del(head);break;
case 4:over();break;
default:printf("\n\t※输入错误!请重新输入<1--4>");
}
getchar();
}
system("pause");
}
//注:信息都保存在Members.lang这个文件中。