用C语言写一个班级添加的程序
答案:1 悬赏:0 手机版
解决时间 2021-11-20 00:02
- 提问者网友:寂寞撕碎了回忆
- 2021-11-19 08:52
用C语言写一个班级添加的程序
最佳答案
- 五星知识达人网友:白昼之月
- 2021-11-19 09:03
程序写错了,调整如下:
void addclass()
{
int i,f=0;
char pname[20];
printf("请输入新班级名:");
scanf("%s",pname);
for(i=0;i {
if (strcmp(cla[i].bianhao, pname)==0)
{
printf("已有此班级!");
system("pause");
system("cls");
return;
}
}
if(i==x) //正常退出循环才表示新增班级为不重复班级,此时i==x
{
strcpy(cla[x].bianhao,pname);
cla[x].renshu = 0;
if ((fpp = fopen("banji.txt","a+")) == NULL)
{
printf("打开文件错误!");
exit(1);
}
fwrite(&cla[x], sizeof(struct Class), 1, fp);
x++;
printf("增加班级%s班成功!\n", pname);
printf("目前班级数:%d\n", x);
fclose(fpp);
system("pause");
system("cls");
}
}
void addclass()
{
int i,f=0;
char pname[20];
printf("请输入新班级名:");
scanf("%s",pname);
for(i=0;i
if (strcmp(cla[i].bianhao, pname)==0)
{
printf("已有此班级!");
system("pause");
system("cls");
return;
}
}
if(i==x) //正常退出循环才表示新增班级为不重复班级,此时i==x
{
strcpy(cla[x].bianhao,pname);
cla[x].renshu = 0;
if ((fpp = fopen("banji.txt","a+")) == NULL)
{
printf("打开文件错误!");
exit(1);
}
fwrite(&cla[x], sizeof(struct Class), 1, fp);
x++;
printf("增加班级%s班成功!\n", pname);
printf("目前班级数:%d\n", x);
fclose(fpp);
system("pause");
system("cls");
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯