krotkruton
Programmer
I've been working on a creating my own barmonkey and I've run into problems while reading in from a file (I think that's the problem). I need to take the entries from the file and insert them into an array in my program. The file is text file with multiple entries of drinks and their ingredients and amounts. It is in the format of
Where N has a maximum of 16 I think.
Here are the first and last two entries of the file.
I put those "ENDOFFILE" strings at the end as a way to exit the file because I couldn't remember how determine when the end of the file is reached. I know its not a great way to do things, but I don't think that it should be causing my problem.
The array that each entry is entered into is in the form of "drinks" which is basically a string for the name and then another array of strings for the ingredient and array of double for the amounts.
The code that I use to load the drink database from the file is:
I thought this would all be pretty straightforward, but I think I am messing things up with the multiple use of getline. Anyway, I get the error "The instruction at "0x0042b75d" referenced memory at "0x40019999". The memory could not be "read"." Which I then click "ok" to and is followed by another error with different memories. Then the program just terminates.
I've got a feeling that this is something simple that I just keep missing, but I've been working on it for a few days and just can't get past it.
Any help is appreciated.
Sorry about not putting this all in a better form but I'm still getting used to this forum.
Code:
Name
Ingredient1 : Amount1
Ingredient2 : Amount2
...
IngredientN : AmountN
end
Here are the first and last two entries of the file.
Code:
44
amaretto : 2.2
cranberry : 5.8
end
73 Bus
cranberry : 1.6
gin : 4.8
triplesec : 1.6
end
.
.
.
1 oz Vodka
vodka : 1.0
end
1 oz Whiskey
whiskey : 1.0
end
ENDOFFILE
ENDOFFILE
ENDOFFILE
ENDOFFILE
I put those "ENDOFFILE" strings at the end as a way to exit the file because I couldn't remember how determine when the end of the file is reached. I know its not a great way to do things, but I don't think that it should be causing my problem.
The array that each entry is entered into is in the form of "drinks" which is basically a string for the name and then another array of strings for the ingredient and array of double for the amounts.
The code that I use to load the drink database from the file is:
Code:
void loadDrinkDB(ifstream drinkDB)
{
int i = 0;
int j = 0;
string currentInput = "";
getline (drinkDB, currentInput);
while (currentInput != "ENDOFFILE") {
drinkList[i].name = currentInput;
drinkDB >> currentInput;
while (currentInput != "end") {
drinkList[i].ingredientName[j] = currentInput;
drinkDB >> currentInput;
drinkDB >> currentInput;
string doubleString, string_object(currentInput);
drinkList[i].ingredientAmounts[j] = atof(string_object.c_str());
drinkDB >> currentInput;
++j;
}
j = 0;
getline (drinkDB, currentInput);
getline (drinkDB, currentInput);
getline (drinkDB, currentInput);
++i;
}
numDrinksInDB = i;
}
I thought this would all be pretty straightforward, but I think I am messing things up with the multiple use of getline. Anyway, I get the error "The instruction at "0x0042b75d" referenced memory at "0x40019999". The memory could not be "read"." Which I then click "ok" to and is followed by another error with different memories. Then the program just terminates.
I've got a feeling that this is something simple that I just keep missing, but I've been working on it for a few days and just can't get past it.
Any help is appreciated.
Sorry about not putting this all in a better form but I'm still getting used to this forum.