Have a project I am working on. Basically, The getFileLength function should accept a filename (an array of characters) as an
argument and return an integer that states how large the file is, in number of characters. I am having difficulty being able to count the number char, any ideas? I am also getting error in MAIN, stating inFile and arr are undefined, not sure why. Thank you. (Also I am not allowed to use any String FCNS)
arr is a single char. So this: inFile >> arr;
reads in a single char. One byte.
Then, you do this: for (int i = 0; i < arr; i++){
What are you trying to do with i < arr ?
i is a number, arr is a character. So you're saying something like: for (int i = 0; i < 'j'; i++){
for example, if the character in question happened to be 'j'.
And then you're counting up from 0 to 'j'. What? What?
I see what your saying, Arr is basically just one element. So, how am I to count how chars. of the file I am trying to read without knowing how large to make Arr, or should I even be using an array to do this. Hmmm...
A very simple way would be to read in a character, and add one to the count, and read in a character, and add one to the count, and read in a character, and add one to the count, and so on, until you reach the end of the file.