} } } print(h); }
void chubanshesort(struct book *head) /*按出版社排序*/ { struct book *p,*t,*f,*h; char ch[20]; int i;
h=t=f=p=head;
if(head==NULL) {printf(\未打开任何文件\ f=p->next;
for(p=head;p->next!=NULL;p=p->next) {
for(t=head,f=t->next;t->next!=NULL;f=f->next,t=t->next) {
if(strcmp(t->chubanshe,f->chubanshe)>0) {
strcpy(ch,t->number ); strcpy(t->number,f->number); strcpy(f->number,ch);
strcpy(ch,t->shuming ); strcpy(t->shuming,f->shuming); strcpy(f->shuming,ch); i=t->shuliang ;
t->shuliang=f->shuliang; f->shuliang=i;
i=t->jiage ; t->jiage=f->jiage; f->jiage=i;
strcpy(ch,t->zhuanye); strcpy(t->zhuanye,f->zhuanye);
strcpy(f->zhuanye,ch);
strcpy(ch,t->zuozhe); strcpy(t->zuozhe,f->zuozhe); strcpy(f->zuozhe,ch);
strcpy(ch,t->chubanshe);
strcpy(t->chubanshe,f->chubanshe); strcpy(f->chubanshe,ch);
strcpy(ch,t->beizhu); strcpy(t->beizhu,f->beizhu); strcpy(f->beizhu,ch); } } } print(h); }
void shumingsearch(struct book *head) /*按教材名称查找*/ { struct book *p; char name[20];
int c;
if(head==NULL) {printf(\未打开任何文件\ printf(\,查找专业 2,查找教材名称:\ scanf(\ getchar();
if(c==2)
printf(\请输入要查找的教材名称:\
else printf(\请输入要查找的专业:\ gets(name); p=head; do{ if(c==2)
if(strcmp(p->shuming,name)==0) {
printf(\教材编号:%s\\n教材名称:%s\\n数量:%d\\n价格:%d\\n专业:%s\\n作者:%s\\n出版社:%s\\n备
注:%s\\n\anshe,p->beizhu); } if(c==1)
if(strcmp(p->zhuanye,name)==0)
{
printf(\教材编号:%s\\n教材名称:%s\\n数量:%d\\n价格:%d\\n专业:%s\\n作者:%s\\n出版社:%s\\n备
注:%s\\n\anshe,p->beizhu); }
p=p->next; }while(p!=NULL); printf(\查找完成\ return; }
struct book *add(struct book *head) /*增加记录*/ { struct book *p,*e,*f,*h;
if(head==NULL) {printf(\未打开任何文件\ h=f=e=head;
p=(struct book *)malloc(sizeof(struct book)); printf(\教材编号:\ gets(p->number); printf(\教材名称:\ gets(p->shuming); printf(\数量:\ scanf(\ printf(\价格:\ scanf(\ getchar(); printf(\专业:\ gets(p->zhuanye); printf(\作者:\ gets(p->zuozhe); printf(\出版社:\ gets(p->chubanshe); printf(\备注:\
gets(p->beizhu);
if(strcmp(f->number,p->number)>0) { p->next=f;h=p;printf(\添加成功\ if(f->next==NULL) { f->next=p;p->next=NULL;printf(\添加成功\ do{
if(f->next!=NULL)
if(strcmp(f->number,p->number)>0) {
e->next=p;p->next=f;printf(\添加成功\ }
if(f->next==NULL) {
f->next=p;
p->next=NULL; printf(\添加成功\ return h; } f=f->next; e=e->next; }while(1); }
struct book *delet(struct book *head) /*删除记录*/ { struct book *p,*e;
char num[20];
if(head==NULL) {printf(\未打开任何文件\ printf(\请输入要删除的教材编号:\ scanf(\ p=e=head;
if(strcmp(p->number,num)==0) { head=head->next; print(head);return head;} else p=p->next; do{
if(strcmp(p->number,num)==0) {
if(p->next!=NULL)
e->next=p->next; if(p->next==NULL) e->next=NULL;
print(head); return head; }
p=p->next; e=e->next; }while(p!=NULL);
printf(\搜索完毕,未找到该记录\ return head; }
struct book *change(struct book *head) /*修改记录*/ { struct book *p;
char num[20];
if(head==NULL) {printf(\未打开任何文件\ printf(\请输入要修改的教材编号:\ scanf(\ getchar(); p=head; do{
if(strcmp(p->number,num)==0) {
printf(\教材编号:%s\\n教材名称:%s\\n数量:%d\\n价格:%d\\n专业:%s\\n作者:%s\\n出版社:%s\\n备
注:%s\\n\anshe,p->beizhu);
printf(\教材编号:\ gets(p->number); printf(\教材名称:\ gets(p->shuming); printf(\数量:\ scanf(\ printf(\价格:\ scanf(\ getchar(); printf(\专业:\ gets(p->zhuanye); printf(\作者:\ gets(p->zuozhe); printf(\出版社:\ gets(p->chubanshe); printf(\备注:\