Help with functions/files

Pages: 12
Hello w0rd,

Line 37 is not needed. It is a call that is not needed or setup right. Line 37 should look like line 38 if it could be used.

Line 28 the value if i is never changed,so everything goes into input[0]. Also not a good idea to check for "eof" because it does not always work the way you would expect. "eof" is only set after a bad read andby then it could be to late by the time you check for "eof". The code is better written as:
1
2
3
4
5
6
7
8
9
10
11
12
13
if (textfile.is_open())
{
	while (textfile >> input[i])
	{
		i++;
	}
}
else
{
	std::cout << "\n Error opening file." << endl;
	Sleep(3000);
	exit(1);
}


Just to let you know the program does work with the changes I made.

Hope that helps,

Andy
Hey Andy,

Thank you so much for taking time out of your day to explain the things I wasn't understanding properly. I did exactly what you said and the program runs flawlessly! Also, thank you for explaining eof, I always thought you put eof when reading files. Thank you again, you are awesome!

Thank you

w0rd
Last edited on
Topic archived. No new replies allowed.
Pages: 12