My program accepts a file that contains names. It looks like:
With the following code it works fine (as long as there are no extra lines or spaces after a name or at the beginning or end of a file)Code:
So, the getline reads the names into "name". However, if there are any spaces, it will count the spaces as part of the name or a new name if the spaces are on a separate line. I want it to ignore spaces. So, after searching through the forum, i saw the suggestion to make the getline:Code:
So, i tired this. When i ran my program again, it got caught in an endless loop. So, i figured it was:Code:
inFile.getline(name, 20, ' ');
So, i wasn't sure what to put here. I read somewhere that i could do:Code:
When i do this, my program crashes.Code:
So, i want to stay in the loop until there are no more names to read, and i do not want to read spaces into name.