c - 我试图允许用户将成员添加到结构数组中。我对 c 很陌生,所以我不确定要去做。代码链接如下
问题描述
这是我正在尝试构建的功能
int addequip(){
printf("\t\t***Add Equipment***");
int Eqicount=0;
int equip_in;
printf("\n\nDo you want to add a Item?");//asks the user if they would like to add an item
scanf("%d",equip_in);
if(equip_in= 1);{
printf("Enter Item:\n");
Eqicount++;
Inven[Eqicount].itemdes;
printf("Do you want to add another?");
}
return 0;
}
这是整个代码
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct lionsequip
{
char itemdes[30];
int amt;
}equipment;
equipment Inven[20];
int loadlist();//loads list from a text file
int addequip();//adds equipment to list
int equipreport();//prints equipment report to a text file
int submenu();
int main(){
loadlist();
submenu();
return 0;
}
int submenu() {//allows the selection of functions
int select;
printf("***Welcome to the Moka Lions System***\n\n\n");
printf("Choose an option below\n\n");
printf("Equipment Report:1\nAdd Equipment:2\nExit:0");
printf("\n\nSelection:");
scanf("%d",&select);
while(select!=0){
switch(select)
{
case 1: equipreport();
break;
case 2: addequip();
break;
default:
printf("Invalid Selection!");
}
return 0;
}
}
int loadlist(void){
char itemdes[30];
int amt;
int i=0;
FILE*fp;
fp=fopen("EquipList.txt","r");
fscanf(fp,"%s",itemdes);
while(strcmp(itemdes,"END")!=0){
fscanf(fp,"%d",&amt);
Inven[i].amt=amt;
strcpy(Inven[i].itemdes,itemdes);
printf("Item:%s\n",itemdes);
printf("Amount:%d\n\n",amt);
fscanf(fp,"%s",itemdes);
printf("***Your List has been loaded***\n\n");
}
return 0;
}
int equipreport(){
FILE*inn=fopen("EquipList.txt","r");
FILE*out=fopen("Report.txt","w");
char itemdes[30];
int amt;
int i;
for(i=0; i<12; i++){
fscanf(inn,"%s %d",itemdes,&amt);
fprintf(out,"%-15s \n%5d \n",itemdes,amt);
}
fclose(inn);
fclose(out);
printf("Your Equipment Report has been Loaded");
}
int addequip(){
printf("\t\t***Add Equipment***");
int Eqicount=0;
int equip_in;
printf("\n\nDo you want to add a Item?");//asks the user if they would like to add an item
scanf("%d",equip_in);
if(equip_in= 1);{
printf("Enter Item:\n");
Eqicount++;
Inven[Eqicount].itemdes;
printf("Do you want to add another?");
}
return 0;
}
解决方案
推荐阅读
- javascript - 如何让用户在他们的计算机上加载和播放 MP4 文件?
- python - 如何获得图像分类模型的测试精度
- c# - 我没有在 rdlc 报告上设置任何边框,但打印后显示红色边框。任何边界都可以告诉我如何删除它吗?
- linux - 如何在 bash 中使用 IF 对列表进行测试
- scala - 如何从火花中的前一组获得价值?
- html - 网格中的 IMG html css
- java - AmazonS3Exception:授权标头格式错误;该地区是错误的
- python - 弃用警告:`np.bool`
- node.js - 在redis中缓存用户权限,好主意吗?
- java - Sprint Boot 中的 Azure AD OAuth 集成提供 401 Unauthorized