1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
void menuCall(string parameters, Bookstore bookstore)
{
ifstream in;
int i, o, option;
int j = 0, p = 0;
string optionToken, bookToken, book;
string *sp, *so;
Book newBook;
sp = new string[5];
so = new string[4];
while (parameters != "") //Check if the string is empty
{
i = parameters.find(",", 0); //Find next comma in the string
if (i > 0) //If a comma is found
{
optionToken = parameters.substr(0, i); //Substring ends at first comma
parameters.erase(0, i + 1); //Delete substring and comma from original string
while (optionToken[0] == ' ') //Check for spaces at beginning of token
{
optionToken.erase(0, 1); //Delete spaces at beginning of token
}
}
if (i < 0) //If no comma is found
{
optionToken = parameters; //Substring ends at the end of the original string
parameters.erase(0, i); //Delete substring from original string
while (optionToken[0] == ' ') //Check for spaces at beginning of token
{
optionToken.erase(0, 1); //Delete spaces at beginning of token
}
}
sp[j] = optionToken; //Token is added to dynamic array
j++; //Keeps track of iterations
}
option = stoi(sp[0]); //Change option number from string to usable int
switch (option) //Switch to determine what menu option is to be performed
{
case(1): //Case 1
in.open(sp[1]); //Open file from extracted token containing file name
while (!in.eof())
{
getline(in, book); //Get string containing book information from input file file
while (book != "") //Check if the string is empty
{
o = book.find(",", 0); //Find the next comma in the string
if (o > 0) //If a comma is found
{
bookToken = book.substr(0, o); //Substring ends at first comma
book.erase(0, o + 1); //Delete substring and comma from original string
while (bookToken[0] == ' ') //Check for spaces at beginning of token
{
bookToken.erase(0, 1); //Delete spaces at beginning of token
}
}
if (o < 0) //If no comma is found
{
bookToken = book; //Substring ends at the end of the original string
book.erase(0, o); //Delete substring from original string
while (bookToken[0] == ' ') //Check for spaces at beginning of token
{
bookToken.erase(0, 1); //Delete spaces at beginning of token
}
}
so[p] = bookToken; //Token is added to dynamic array
p++; //Keeps track of iterations
}
}
break;
|