更新 '1.c'
Signed-off-by: xtaodada <xtao@xtaolink.cn>
This commit is contained in:
parent
4bef6527e5
commit
84e2158bd6
47
1.c
47
1.c
@ -4,13 +4,15 @@
|
||||
#define MAX 100
|
||||
#define MAX_1 100
|
||||
typedef struct singer{
|
||||
int num;
|
||||
char name[10];
|
||||
char xb[10];
|
||||
int score[MAX_1];
|
||||
int num; // 序号
|
||||
char name[10]; // 姓名
|
||||
char xb[10]; // 性别
|
||||
float aver; // 平均分
|
||||
int score[MAX_1]; // 原始成绩
|
||||
}SING;
|
||||
|
||||
void inarray(SING sing[MAX], int *pnum){
|
||||
// 输入歌手信息:序号、姓名、性别
|
||||
int n=0;
|
||||
printf("输入歌手人数:");
|
||||
scanf("%d", &n);
|
||||
@ -22,25 +24,48 @@ void inarray(SING sing[MAX], int *pnum){
|
||||
*pnum = n;
|
||||
}
|
||||
void outarrry(SING sing[MAX], int n){
|
||||
// 输出歌手信息:序号、姓名、性别
|
||||
printf("序号\t姓名\t性别\n");
|
||||
for(int i=0;i<n;i++){
|
||||
printf("%d\t%s\t%s\n",sing[i].num,sing[i].name,sing[i].xb);
|
||||
}
|
||||
}
|
||||
void insert(SING sing[MAX], int *pnum){
|
||||
// 新增歌手信息:序号、姓名、性别(增加到最后)
|
||||
int n=*pnum;
|
||||
printf("请输入第%d个歌手的信息:\n",n);
|
||||
printf("序号\t姓名\t性别\n");
|
||||
scanf("%d%s%s",&sing[n].num,sing[n].name,sing[n].xb);
|
||||
*pnum=n+1;
|
||||
}
|
||||
int search_num(SING sing[MAX], int num, int x){
|
||||
void save(SING sing[MAX], int num, int num_){
|
||||
// 保存数据到文件
|
||||
FILE *fp;
|
||||
char filename[10];
|
||||
|
||||
}
|
||||
printf("请输入文件名:");
|
||||
scanf("%s", filename);
|
||||
|
||||
// 打开文件
|
||||
if((fp=fopen(filename, "w"))==NULL){
|
||||
printf("无法打开该文件,可能是文件名有误!\n");
|
||||
return;
|
||||
}
|
||||
// 写入文件
|
||||
fprintf(fp, "当前共有%d个歌手,%d个评委:\n",num,num_);
|
||||
fprintf(fp, "序号\t姓名\t性别\t成绩\n");
|
||||
for(int i=0;i<num;i++){
|
||||
fprintf(fp,"%d\t%s\t%s",sing[i].num,sing[i].name,sing[i].xb);
|
||||
for(int n=0;n<num_;n++){
|
||||
fprintf(fp,"\t%d",sing[i].score[n]);
|
||||
}
|
||||
fprintf(fp,"\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
SING sing[MAX];
|
||||
int num=0;
|
||||
int num=0,num_=0;
|
||||
int choice;
|
||||
|
||||
while(1){
|
||||
@ -75,9 +100,11 @@ int main(){
|
||||
insert(sing,&num);
|
||||
break;
|
||||
case 9:
|
||||
save(sing,num);
|
||||
save(sing,num,num_);
|
||||
break;
|
||||
case 10:
|
||||
load(sing,&num,&num_);
|
||||
break;
|
||||
case
|
||||
default:
|
||||
printf("调用输入错误函数\n");
|
||||
break;
|
||||
@ -90,4 +117,4 @@ int main(){
|
||||
}
|
||||
printf("感谢使用,再见!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user