If i use "if (cells->states == NULL)" it doesn't do anything, thus the malloc function should succeed.
The problem is in Array_Get: It can't return the value pointed to by the pointer
If i use "if (cells->states == NULL)" it doesn't do anything, thus the malloc function should succeed.
The problem is in Array_Get: It can't return the value pointed to by the pointer
Last edited by Brafil; 12-03-2008 at 11:42 AM.
> memset(cells, 0, sizeof(*cells));
And this trashes the pointers to the memory you just allocated in the previous lines.
Just as we thought we were getting somewhere explaining arrays, you suddenly decide to enter a whole new race on a whole new horse.
Only this horse is a real buckaroo and you're in for a rough ride!
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Yes I know, but I'm starting to feel better with pointers than with arrays. So memset is the bad guy? How can I undergo this?
memset the result of malloc, for the amount you asked for.
Or use calloc(), which achieves the same thing.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Wow! Now it works! Thanks for helping a newb!
Sorry, but Now, when I calculate and draw two times, it crashes at the very first Array_Get(prev_row, prev_item) position. What might it be?
PS: It doesn't really crash, but it says return value 3, and I don't have any exit(3) specified.
Last edited by Brafil; 12-05-2008 at 10:14 AM.
Most compilers come with a debugger.
The Visual Studio Express debugger is very nice.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
But I remarked that AllocConsole etc. seems to be undefined?
EDIT: Solved. I wrote it all again (And tested at every step. It seemed as when I replace some pointers with real variables, it works. What's that? How can I prevent that?)