为了账号安全,请及时绑定邮箱和手机立即绑定

求教C语言前辈

求教C语言前辈

C
Camel97 2016-01-26 17:55:57
void input(struct product *p,int n){ n++; char str[20]; printf("输入设备编号:"); gets(str); p->num=atoi(str); printf("输入设备类型:"); gets(p->type);}这里为什么显示出来的是  输入设备编号:输入设备类型:也就是说两个是一起显示出来,我就不能给设备写编号另外,对于已有设备的信息怎么删除?对符合要求的直接把设备编号变成0然后只考虑所有编号大于0的设备这样算不算删除?下面是部分代码,要求对设备信息添加,删除,浏览,查找#include<stdio.h>#include<stdlib.h>#include<math.h>#define N 100struct product{ int num;                       //设备编号 char type[20];             //设备类型 char name[20];         //设备名称 float price;                  //设备价格 long in_time;              //入库时间 char inper_name[20];                  //经手人 char yes_no;               //是否在库 long out_time;           //外借时间 char outper_name[15];           //外借人 long re_time;                   //归还时间};void input(struct product *p,int n);                  //添加void del(struct product *p,int n);                         //删除void scan(struct product *p,int n);                     //浏览void find(struct product *p,int n);                         //查找int system(const char *string);int main(){ struct product pro[N]; int i; int number=0; printf("***************************************************************\n"); printf("* 1.添加新设备                        2.删除已有设备          *\n"); printf("* 3.浏览所有设备信息                  4.查询某一设备并显示信息*\n"); printf("***************************************************************\n"); printf("请用数字选择你需要的功能:"); scanf("%d",&i); system("cls");                  //清屏操作 switch(i) { case 1: input(pro,number);      break; } return 0;}void input(struct product *p,int n){ n++; char str[20]; printf("输入设备编号:"); gets(str); p->num=atoi(str); printf("输入设备类型:"); gets(p->type); printf("输入设备名称:"); gets(p->name); printf("输入设备价格:"); gets(str); p->price=atoi(str); printf("输入设备入库时间 如20150101:"); gets(str); p->in_time=atoi(str); printf("输入经手人名字:"); gets(p->inper_name); printf("设备是否在库?输入yes or no:"); gets(str); p->yes_no=str[0]; if(p->yes_no=='n'){ printf("输入外借时间 如20150101:"); gets(str); p->out_time=atoi(str); printf("输入外借人姓名:"); gets(p->outper_name); printf("输入归还时间 如20150101:"); gets(str); p->re_time=atoi(str); }else{ p->out_time=0; p->re_time=0; }}
查看完整描述

1 回答

已采纳
?
MadMarical

TA贡献79条经验 获得超122个赞

你好。从代码逻辑上和语法上是没有错误的,但是gets方法由于其安全性现在已经被移除了,请先确认你的编译器是否支持gets方法,可以改为scanf方式试一试,我试了没有问题。

对于删除,删除这个东西是相对而言的,只要你能将这个元素排除在想计算的元素之外当然算是删除了。另外,针对你使用的数据结构,完全可以添加一个bool isDelete 的字段来标记这段数据是否有效。如果符合删除条件,isDelete为true,遍历数组时略过即可。

查看完整回答
1 反对 回复 2016-01-26
  • 1 回答
  • 0 关注
  • 1684 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信