The idea of this code is to read the information in a file, which will consist of a string of random letters, and save it to an array so I can use at information later.
But, for some reason, when compiled, this code does not let the user type anything when prompted. That is, it gets to the "Please give file name: " line, and completely locks up.
What am I doing wrong here?
I'm going to bump this.
Assistance with this issue would be very much appreciated. I am completely stuck and I can't seem to find any relevant tutorials.
j is an integer, you will fail if you try to read a letter with an integer. file gets in a state of error and never reach file.eof()
Read your file like this while( file >> var ){
Also cin.getline(filename, sizeof(filename)-1); Don't forget that it must end with '\0'
This is an improvement from where I got myself after a bit of experimenting. I locked this entire file processing bit into a function on its own that the program can call on later, and, up until implementing your fix, the program completely crashed when I tried to use this part.
The array Read[] is a global variable, not initialized in this function.
Don't check for eof. while(file >> y) is already doing that (when it reaches eof, the condition will be false) while( file>>Read[x] ) x++; That's all you need.