标题:[求助]急如救火
只看楼主
wayne2121
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-7-1
 问题点数:0 回复次数:4 
[求助]急如救火

蓝色部分有错误,求助于高手,请帮忙更正
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MUNMAX 5
struct bookInfo{
int num;
char* name;
char* writer;
char* press;
float price;
};
struct bookType{
bookInfo book [MUNMAX];
int num;
};
void DisplayMenu();
int choiceItem();
void Init(struct bookType*);
void PrintInfo(struct bookType);
void Print_aInfo(struct bookType,int);
void Input_aInfo(struct bookInfo*);
void Input_allInfo(struct bookType*,int num);
int Search(struct bookType);
void Delete(struct bookType*);
void main()
{

struct bookType book;
int choice,index;

Init(&book);
do{
choice=choiceItem();
switch (choice){
case 0:printf("\nWelcome to\n");break;
case 1:Input_allInfo(&book,MUNMAX);break;
case 2:Input_allInfo(&book,1); break;
case 3:PrintInfo(book);break;
case 4:Init(&book);break;
case 5:if ((index=Search(book))!=-1)
Print_aInfo(book,index);
else printf("\n No eixst the book.");
break;
case 6:Delete(&book);break;
}
}while(choice);
}

void DisplayMenu()
{
printf("\n=========MENU =========");
printf("\n 1........Input_allInfo\n");
printf("\n 2........Input_allInfo\n");
printf("\n 3........PrintInfo\n");
printf("\n 4........Init\n");
printf("\n 5........Search\n");
printf("\n 6.........Delete\n");
printf("\n 0.........Exit System\n");
printf("\n Chioce:");
}

int choiceItem()
{
int choice;
do{
DisplayMenu();
scanf("%d",&choice);
}while(choice<0||choice>6);
return choice;
}

void Init(struct bookType* b)
{
b->num=0;
}

void Print_aInfo(struct bookType b,int index)
{
printf("\n%4d %-10s",b.book[index].num,b.book[index].name);

printf("%4s%4s%4f",b.book[index].writer,b.book[index].press,b.book[index].price);
}

void PrintInfo(struct bookType b)
{

if (b.num==0) {
printf("\nNo book.\n");
return;
}
for (int i=0;i<b.num;i++){
printf("\n%4d %-16s",b.book[i].num,b.book[i].name);
printf("%4s%4s%6.1f",b.book[i].writer,b.book[i].press,b.book[i].price);
}
}

void Input_aInfo(struct bookInfo* ab)
{

scanf("%d",&ab->num);
ab->name=(char*)malloc(30);
scanf("%s",ab->name);
ab->writer=(char*)malloc(30);
scanf("%s",&ab->writer);
ab->press=(char*)malloc(30);
scanf("%s",&ab->press);
scanf("%f",&ab->price);
}

void Input_allInfo(struct bookType* b,int num)
{
printf("\nInput %d book num\n",num);
for (int i=0;i<num;i++){
if (b->num==MUNMAX){
printf("\nOverflow.");
break;
}
Input_aInfo(&b->book[b->num++]);
}
}

int Search(struct bookType book)
{
int num;

printf("\nInput num:");
scanf("%d",&num);
for (int i=0;i<book.num;i++)
if (book.book[i].num==num)
return i;
return -1;
}

void Delete(struct bookType*)
{


}

搜索更多相关主题的帖子: 救火 
2006-07-01 22:51
dqh3000
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-7-1
得分:0 
这么长,还是main出问题,switch没有default吧,不过这个不一定是问题所在
设断点跟踪吧……

睡觉觉了……

2006-07-02 00:35
–★–
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1512
专家分:0
注 册:2006-5-1
得分:0 
刚刚试过了,如果按照*.cpp进行编译,根本没有语法
错误,也能运行。当然*.c即按C编译就有39处错误了。
具体请楼主明示,究竟是哪(几)个功能失常?

落霞与孤鹜齐飞,秋水共长天一色! 心有多大,路有多宽。三教九流,鸡鸣狗盗。兼收并蓄,海纳百川。
2006-07-02 06:07
soft_wind
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:1430
专家分:0
注 册:2006-4-5
得分:0 
dgKG5cAm.txt (2.8 KB) [求助]急如救火


对不礼貌的女生收钱......
2006-07-02 18:51
zhao5195
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-6-15
得分:0 
太长了没心思看!!!

2006-07-03 18:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-76117-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.432370 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved