该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
回复7楼:#include
#include
#include
struct PeoPle
{
int num;
char name[20];
long int pho;
}Peo[500];
void Jiemian()
{
system("cls");
printf("\n\n\n\n\n");
printf("\t\t|-------------------STUDENT---------------------|\t\t");
printf("\t\t|\t0.跳出程序 |\n");
printf("\t\t|\t1.输入新电话号码 |\n");
printf("\t\t|\t2.修改电话号码 |\n");
printf("\t\t|\t3.删除电话号码 |\n");
printf("\t\t|\t4. |\n");
printf("\t\t|\t5. |\n");
printf("\t\t|\t6. |\n");
printf("\t\t|\t7. |\n");
printf("\t\t|-----------------------------------------------|\t\n");
printf("\t\t\tchoose(0-7):\n");
}
/*
void Panduan(int m,int inum);
void Xiugai(int m,int inum)
{
FILE * fp;
int LEN=sizeof(struct PeoPle);
while(!feof(fp))
if(fread(&Peo[inum],LEN,1,fp)==1)
inum++;
fclose(fp);
if(inum==0)
{
printf("没有记录!\n");
Jiemian();
scanf("%d",&m);
Panduan(m,inum);
}
}
*/
void put(int inum)
{ FILE *fp;
int i;
Peo->num=inum;
printf("请输入成员名字:");
scanf("%s",&Peo[inum].name);
printf("请输入号码:");
scanf("%d",&Peo[inum].pho);
if((fp=fopen("phone","wb+"))==NULL)
{
printf("文件打开失败\n");
return ;
}
fwrite(&Peo[inum],sizeof(struct PeoPle),1,fp);
fclose(fp);
fread(&Peo[inum],sizeof(struct PeoPle),1,fp);
printf("信息已经保存,如下\n");
for(i=0;i<=inum;i++)
{
printf("NO.%d:名字:%s,电话号码:%d\n",i,Peo[i].name,Peo[i].pho);
}
fclose(fp);
}
void input(int inum)
{
char ch[2];
printf("你要输入新的号码吗?(y\n)?");
scanf("%s",&ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)
{
put(inum);
}
else if(strcmp(ch,"N")==0||strcmp(ch,"n")==0)
{
printf("你选择了退出程序,按任意键结束\n");
return;
}
else
{
printf("你的输入有误,请重新输入选择\n");
input(inum);
}
}
void Panduan(int m,int inum)
{
char ch[2];
switch(m)
{
case 0:
printf("你确定退出程序?(Y/N)?");
scanf("%s",&ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)
{
printf("已经选择退出程序\n");
return;
}
else
{
Jiemian();
scanf("%d",&m);
Panduan(m,inum);
}
case 1:
input(inum);
break;
/*
case 2:
Xiugai(m,inum);
break;
*/
default:
return;
}
}
void main()
{
FILE * fp;
int m;
int inum=0;
int LEN=sizeof(struct PeoPle);
if((fp=fopen("phone","ab+"))==NULL)
{
printf("文件错误\n");
return;
}
if(fread(&Peo[inum],LEN,1,fp)==1)
{
inum++;
}
inum++;
Jiemian();
scanf("%d",&m);
Panduan(m,inum);
}