蓝色部分有错误,求助于高手,请帮忙更正
#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*)
{
}
----------------解决方案--------------------------------------------------------
这么长,还是main出问题,switch没有default吧,不过这个不一定是问题所在
设断点跟踪吧……
睡觉觉了……
----------------解决方案--------------------------------------------------------
刚刚试过了,如果按照*.cpp进行编译,根本没有语法
错误,也能运行。当然*.c即按C编译就有39处错误了。
具体请楼主明示,究竟是哪(几)个功能失常?
----------------解决方案--------------------------------------------------------
----------------解决方案--------------------------------------------------------
太长了没心思看!!!
----------------解决方案--------------------------------------------------------