I am reading from a file into a 2-D array in c++. I used a do while loop together with the eof()
. The problem I was facing was, the program continues to read empty spaces when the characters in the file are exhausted. I realized that it was because of the getline function, so I used the get function instead. The program compiles and runs successfully but upon reaching the point where the characters in the file is to be read,(i.e in my console), the programs stops suddenly and returns with this error code -1073741795 (0xc00000ID). I would like to know why though, my major concern is how I will be able to read from the file and after the characters in the file is exhausted, the program stops reading from the file (so that no empty spaces are read).
Here is the sample code:
int k=0;
do{
name_input.getline(sample[k],num_char);
k++;
} while (!name_input.eof());
num=k-1;
PS: The input file is in the form; Mr. Clark Smith John B. Doe Joshua Clement Johnson each on one line in a .txt file (notepad), after the 3rd name is empty space which my program still reads.