My problem is that it runs though strcpy(*Ingrediants, temp) the first time then run times out the second time though.
This code is meant to populate a dynamic array using all the words from a .txt I made myself.
Does anyone know why this is happening?
Code:int main() { char ** Ingrediants = 0; int * counter = 0; ifstream myfile("pantry.txt"); int i = 0; int numberOfIngrediants = 0; int choice = 0; char goAgain = 'n'; while(goAgain = 'y'){ //Checks to see if file opens. if(myfile.fail()) { cout << "File did not open"; } //Populates ** Ingrediants from "pantry.txt" while(!myfile.eof()) { char temp[30]; myfile.getline(temp, 30, '\n'); char ** Ingrediants = new char*[numberOfIngrediants]; Ingrediants[numberOfIngrediants] = new char (strlen(temp)); strcpy(*Ingrediants, temp); //char ** NewIngrediants = new char*[numberOfIngrediants + 1]; //NewIngrediants = Ingrediants; i++; numberOfIngrediants++; // =======================



1Likes
LinkBack URL
About LinkBacks


