I'm trying to copy a file into an array for analysis.
The error I'm getting is on line 43.
Also, my function at the end...All I did was convert my pseudo-code. If someone could look and tell me if that is going to do what I want it to do (count the characters, words and lines in the array). I've yet to see if it will work because I can't get it to compile past the line 43 error....
Any help or guidance would be greatly appreciated! :D
char currentchar[2048]; // this is a buffer (its name can be confusing)
char* next_char = currentchar; // this is a pointer to the next character
while (!fin.eof())
{
*(next_char++) = fin.get();
}
*next_char = '\0';
But you main problem is that you do maths with currentchar, which is not a pointer but an array.
You could either writechar* currentchar = newchar[length];, which I don't suggest because you will then find it difficult to free the array, or char my_array[length]; char* currentchar = my_array;, though of course if you took my advice and decided to calculate the length of your file (and length would not be constant) you wold have to write char* my_array = newchar[length]; char* currentchat = my_array;.
Good luck
I thought currentchar was an address to the first thing (ie currentchar[0]) in the array.
and char* is a character address... why can't I do math between character addresses? Incrementing the address by 1 would be looking at the next thing in that array (ie currentcount[1], etc)
what are you trying to do with the line 43 of code? currentchar is a pointer and your telling it to be 1 number higher? just use an iterator. create int i and add one to it each time the while loop loops through and access the c stlye string using square brackets just like a normal array.
char currentchar[sizeof(fin)];
int i = 0;
while(!fin.eof)
{
currentchar[i] = fin.get();
i++;
}
i think this should solve that problem if i am correct on what you are trying to do. also i think i you should learn more about c style strings.
sorry if i completely misunderstood you or ur code as i am still a beginner but i do think i am correct
also may i ask how line 39 is compiling. you do not know the size of fin before run time so how can you create an array like that?
a pointer is an address in memory. And currentchar is pointing to the first address in the array. If I increment the address by 1 its pointing to the next item in that array.