定义了一个结构体,后面调用的时候出问题,不知道为什么赋值失败。

定义了一个结构体,后面调用的时候出问题,不知道为什么赋值失败。

#include
#include
#include
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define MAXSIZE 1000    //图书表可能达到的最大长度
using namespace std;
typedef struct
{//图书信息定义
    char no[20];    //图书ISBN
    char name[50];   //图书名字
    float price;   //图书价格
}Book;
typedef struct
{//图书表的顺序存储结构类型为SqList
    Book *elem;                   //存储空间的基地址
    int length;                   //图书表中当前图书个数
}SqList;


int InitList(SqList &L)                
{                                
    L.elem=new Book[MAXSIZE];    
    if(!L.elem)exit(OVERFLOW);                 
    L.length=0;        
    return OK;            
}
 
int Input(SqList &L)         
{
    int i,number,count;
    cin>>number;
    for( i = 0 ; i>L.elem[i].no>>L.elem[i].name>>L.elem[i].price;
        L.length++;
        }
        return OK;   
}

int FindFavorite_Sq(SqList L)
{//最爱图书的查找并输出数据
    SqList Fav;
    cin >> Fav.length;
    for(int i=0;i> Fav.elem[i].name;            //@@@@就是这一步有问题!!! 
        
    for(int m=0;mint n=0;
        for(int i=0;iif(strcmp(Fav.elem[m].name,L.elem[i].name)==0)    n++;
        if(!n)
            cout << "Sorry,there is no your favourite!" << endl;
        else{
            cout << n << endl;
            for(int i=0;iif(strcmp(Fav.elem[m].name,L.elem[i].name)==0){
                    cout << L.elem[i].no << ' ' << L.elem[i].name << ' ';
                    cout << fixed << setprecision(2) << L.elem[i].price << endl;
                }
        }    
    }
    return OK;
}
int main(){
    SqList L;                 
    InitList(L);           
    Input(L);               
    FindFavorite_Sq(L);            
    return 0;    
}
SqList Fav;
cin >> Fav.length;
for(int i=0;i<Fav.length;i++)
    cin >> Fav.elem[i].name; 

这个Fav你还没有初始化啊。先调用InitList(Fav)啊

SqList Fav之后
Fav.elem并没有分配内存。
cin>>Fav.length之后Fav.elem=new Book[Fav.length];