I have a program that wants to read in 30 strings from a text file and store each string in an element of an array.
The array is declared as this...
MAX_COMMANDS is defined as the number 30.Code:char *command[MAX_COMMANDS]; //commands
Here is my function that loads the text file and tries to fill up the array...
Code:int LoadCommands() { int i; ifstream file ("install.txt"); if (!file.is_open()) return ERROR_DOESNOTEXIST; //get the commands for (i=0; i<MAX_COMMANDS; i++) { file.getline(command[i],128); } //done here file.close(); //double check if (file.is_open()) file.close(); return 1; }
I know the answer must be obvious, but i can't figure out how to fix it. I want it so that each line in the text file can be of any length, blank or around 64 characters.
The problem is, when the program gets to the file.getline point, it crashes with an illegal operation i presume to be caused by trying to read something that isn't there. Any help?