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 回答
- 0 關注
- 1786 瀏覽
添加回答
舉報
0/150
提交
取消