由于某种原因,程序总是在我第二次主调用inputHolding()并尝试获取电话号码时崩溃(输入电话号码然后它崩溃)。如何修复此崩溃?这是调用堆栈的图片以及它在我的代码中崩溃的位置:http: //i.imgur.com/zWJ17NC.png
#include <iostream>
#include "LibraryDrv.h"
using namespace std;
int main() {
Holding *hptr[5];
for (int i = 0; i < 5; i++) {
    hptr[i] = inputHolding();
}
for (int i = 0; i < 5; i++) {
    hptr[i]->print();
}
return 0;
}
Holding* inputHolding() {
char selection;
char title[50];
int callNumber = 0;
char author[50];
char performer[50];
char format;
cout << "Enter B for book, R for recording: ";
cin >> selection;
if (selection == 'B') {
    cout << "Enter book title: ";
    cin >> title;
    cout << "Enter book author: ";
    cin >> author;
    cout << "Enter call number: ";
    cin >> callNumber;
    Book* aBook = new Book(title, callNumber, author);
    return aBook;
}
else  if (selection == 'R') {
    cout << "Enter recording title: ";
    cin >> title;
    cout << "Enter performer: ";
    cin >> performer;
    cout << "Enter format: (M)P3, (W)AV, (A)IFF: ";
    cin >> format;
    cout << "Enter call number: ";
    cin >> callNumber;
    Recording* aRecording = new Recording(title, callNumber, performer,     format);
    return aRecording;
}
else {
    cout << "Incorrect selection" << endl;
    return nullptr;
}
}