My program accepts a file that contains names. It looks like:
Code:
dave
john
daniel
...
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:
char name[20];
while(!inFile.eof())
}
inFile.getline(name, 20);
...
}
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:
inFile.getline(name, 20, ' ');
So, i tired this. When i ran my program again, it got caught in an endless loop. So, i figured it was:
Code:
while(!inFile.eof())
So, i wasn't sure what to put here. I read somewhere that i could do:
Code:
while(inFile.getline(name, 20))
When i do this, my program crashes.
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.
Any suggestions?
Thanks