/* 2008-10-27 */
/* tod: 删除, 修改, 参考: 教材P63-67*/
# include<stdio.h>
#define N 1
typedef struct student
{
char xuehao[10];
char xingming[10];
int chengji;
} S ;
void xianshicaidan()
{
printf("\n1 - Initialization.\n");
printf("2 - Enter Scores.\n");
printf("3 - Insert Score.\n");
printf("4 - Display Scores.\n");
printf("0 - Exit System.\n");
}
void Initial(S a[], int length)
{
int i;
printf("Please enter XueHao & Xingming (%d students):\n",length);
for(i=0;i<length;i++)
{
scanf("%s%s",a[i].xuehao,a[i].xingming);
a[i].chengji=0;
}
}
void insert(S a[], int *length)
{
int i,location;
S x;
printf("Please enter location:\n");
scanf("%d",&location);
printf("Please enter XueHao & Xingming & Chengji:\n");
scanf("%s%s%d",x.xuehao,x.xingming,
&x.chengji);
for(i=*length;i>=location+1;i--)
a[i]=a[i-1];
a[location]=x;
(*length)++;
}
void xianshi(S a[], int length)
{
int i;
printf("Display Scores:\n");
for(i=0;i<length;i++)
{
printf("%s %s %d\n",a[i].xuehao,a[i].xingming,
a[i].chengji);
}
}
void main()
{
int menu=1, len=N;
S b[10];
xianshicaidan();
printf("Enter a number to choose opreation:\n");
scanf("%d",&menu);
while(menu!=0)
{
switch(menu)
{
case 1: Initial(b,len);break;
case 4: xianshi(b,len); break;
case 3: insert(b,&len);break;
default: break;
}
xianshicaidan();
printf("Enter a number to choose opreation:\n");
scanf("%d",&menu);
}
}
标签:10,线性表,int,void,Scores,length,printf,2008,顺序存储
From: https://blog.51cto.com/emanlee/8247965