#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student{
char name[20];
int age;
char addr[30];
float score;
};
void addStudentInfo(struct Student stu[],int len,char name[],int age,char addr[],float score){
int i = 0;
int curLen = 0;
for (i = 0; i < len; i++){
if (stu[i].age != 0){
curLen++;
}
else{
break;
}
}
strcpy(stu[curLen].name, name);
strcpy(stu[curLen].addr, addr);
stu[curLen].age = age;
stu[curLen].score = score;
}
void printStudentInfo(struct Student stu[],int len){
printf("66666666666666666\n");
int i = 0;
int curLen = 0;
for (i = 0; i < len; i++){
if (stu[i].age != 0){
curLen++;
}
else{
break;
}
}
printf("curlen = %d\n", curLen);
for (i = 0; i < curLen; i++){
printf("name = %s,age = %d,addr = %s,score = %f\n", stu[i].name, stu[i].age, stu[i].addr, stu[i].score);
printf("*************************************\n");
printf("*************************************\n");
}
}
void changeStudentInfo(struct Student sInfo[],int len, char name[20],int age,char addr[30],float score){
int i = 0;
int num = 0;
for (i = 0; i < len; i++){
if (sInfo[0].age == 0){
break;
}
else
num++;
}
for (i = 0; i < num; i++){
if (!strcmp(sInfo[i].name,name)){
sInfo[i].age = age;
sInfo[i].score = score;
strcpy(sInfo[i].addr, addr);
}
}
}
void main(){
struct Student sInfo[54];
int len = sizeof(sInfo) / sizeof(sInfo[0]);
int item = 0;
char name[20];
char addr[30];
int age = 0;
float score = 0;
memset(sInfo, 0, sizeof(sInfo));
while (1){
puts("请输出你的选项: 0 -- 退出系统 1--增加学员信息 2--删除学员信息 3--修改学员信息 4--打印学员信息 5--查找学员信息 ");
scanf("%d", &item);
printf("item = %d\n", item);
switch (item){
case 1:
addStudentInfo(sInfo,len,"zhansan",20,"xiangyang",87.5);
addStudentInfo(sInfo, len, "wangwu", 20, "xiangyang", 87.5);
addStudentInfo(sInfo, len, "lisi", 18, "zaoyang", 78.5);
addStudentInfo(sInfo, len, "zhaoyun", 20, "xiangyang", 87.5);
break;
case 3:
printf("333333333333333\n");
changeStudentInfo(sInfo,len,"lisi",17,"上海",99.5);
printf("444444444444444444444444\n");
printStudentInfo(sInfo, len);
printf("5555555555555555555555\n");
break;
case 4:
printStudentInfo(sInfo,len);
break;
}
}
Label:
printf("over\n");
system("pause");
}
void main03(){
char buf1[] = "hello world";
printf("%d\n", strcmp(buf1, "hello ld"));
system("pause");
}