机构体数组,按书写的但是运行不了!!!
#include "stdio.h"#define students 45
struct student
{
char number[9];
char name[8];
char department[20];
};
struct address
{
struct student student1;
char telephone[12];
char mobile[11];
unsigned int QQ_number;
};
struct address student_addr[students];
int current_students;
void main()
{
int t;
int choice;
for(t=0;t<=students;t++)
student_addr[t].student1.number[0]=NULL;
while(1)
{choice=operation();
switch(choice)
{ case'1':input();
break;
case'2':output();
break;
case'3':delete();
break;
case'4':return;}
}
}
int operation()
{int c;
printf("\n");
printf("***************通信管理*****************\n");
printf("* *\n");
printf("* 1.录入学生通信信息 *\n");
printf("* 2.显示学生通信信息 *\n");
printf("* 3.删除学生通信信息 *\n");
printf("* 4.退出 *\n");
printf("* *\n");
printf("****************************************\n");
printf("请选择<1-4>: ");
while(1)
{scanf("%d",&c);
if(c<1||c>4)
printf("提示:请按要求输入\n");
else
break;
}
return c;
}
void input()
{int pos;int i;
if(current_students==students)
{ printf("存储空间已用完。\n");
return;}
for(i=0;i<=students;i++)
{if(student_addr[i].student.number[0]==NULL)
break;}
pos=i;
printf("number:");
gets(student_addr[pos].student1t.number);
printf("\nname:");
gets(student_addr[pos].student1.name);
printf("\ndepartment:");
gets(student_addr[pos].student1.department);
printf("\ntelephone:");
gets(student_addr[pos].telephone);
printf("\nmobile:");
gets(student_addr[pos].mobile);
printf("\nQQ_number:");
scanf("%d",&student_addr[pos].QQ_number);
current_students++;
return;
}
void output()
int i;
{ for(int i=;i<=students;i++);
{if(student_addr[i].student.number[0]!=NULL)
printf("number:%s name:%s department:%s telephone:%s mobile:%s QQ_number:%s\n",
student_addr[i].student1.number,student_addr[i].student1.name,student_addr[i].student1.department,
student_addr[i].telephone,student_addr[i].mobile,
student_addr[i].QQ_number);
}
}
void delete()
{ char number[9];
int pos,i;
printf("请输入你想删除通信信息的学生的学号:");
gets(number);
for(i=0;i<=students;i++)
{if(!strcmp(student_addr[i].student.number,number)
)break;}
pos=i;
if(pos>students)
{printf("找不到指定记录,删除没有完成。\n");
return;}
else
{student_addr[pos].student.number[0]=NULL;
printf("成功地将学号为:%s的记录删除!\n",number);
current_student1--;}
return;
}