Opening a file problem

Pages: 12
This is out of bounds of the array but , can take negative values because does not deglared as unsigned so negative can be stored.

So my for is from -3 to 54 loop fills correct my walls.

The problem is not of my walls.

My dungeon crawlling engine is working perfect , even I put negative values in my walls. (Out bounds of my levels array , but in fact
is from minus infinity to plus 55 are my limits of my array.


Ok. I will put this in as simple english as I can.

Yes, you can use a negative number and store a value in it like you are doing. And Yes this will store the value, and Yes you can read it back later. But NO you cannot ensure now that your application will not crash randomly, NO you do not know what memory you have just over-written. Be it another variable, function address, return address, stack pointer.

While you can load into -3 etc fine. Chances are you are over-writing another section of memory that is causing the fread() to crash.

Look at it like this
int array[4];
My stack looks like
1
2
3
4
5
6
7
8
9
unknown // If I used array[-2]
unknown // If I used array[-1]
array[0]
array[1]
array[2]
array[3]
unknown // If I used array [4]
unknown
unknown


So you can assign outside of the bounds. Shit, I could go
1
2
int array[1];
array[939393] = 10;


It'd let me, but chances are it would crash. And that's bad programming, and clearly illustrates no knowledge of arrays.

You clear do not have a basic grasp on arrays and data storage in C++. If you want to make up indexes for your arrays. I would try another language that will give you either A) a compiler error when you try such a stupid mistake or B) allow you to have crap indexes without risk. C++ is neither of those languages.

I have provided you with links on the basics of Arrays. Read it.

We have tried to help you solve your problem. But clearly you do not want any help from us, as you are ignoring it and proclaiming your code is valid. When it is not. Even IF you find a way around the crash you experience now, you will have many more crashes because of the invalid memory writes you are performing.

Ok thank you ,
Now I need to change all of my code which , read negative array elements.

What I do , If am I at 1 x 1 on my map and need to check my front square.
I mean one square y-1.

My horizontal squares are x and my vertical are y.
If I want to check my vertical squares in front of me at position -1 in front of me what I do?

For example I am at 3,5 square and I am checking if 3,4 is something.
Then I am steping forward and I am at square 3,4 I am checking now if at 3,3 is there is something I am keeping moving towords to 3,1 square

Look this example.

http://www.geocities.com/takis76/example2.jpg

You will understand what I am trying to do.

Edit:

Thank you again very very much for your help, I'll try to correct my code.
Last edited on
If that is what you're trying to do, then you also seem to have design problems. But in any case, if you're at square [1][1], you don't need to check [1][-1]. You need to check [1][0]. Duh. If you're at [1][0] you don't need to check anything, as it would (or should) be impossible for the player to move beyond the boundaries of the array.
Now, about those walls... Why are you using different variables for each of the four walls in each square, if all squares end up being just blocks where all walls are solid? Why not just make the map a bitmap of sorts and have it look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
11111111111111111111
10000000000000000001
10000000000000000001
10011111111111111001
10011111111111111001
10011111111111111001
10011111111111111001
10011111111111111001
10011111111111111001
10011111111111111001
10011111111111111001
10011111111111111001
10011111111111111001
10011111111111111001
10011111111111111001
10011111111111111001
10011111111111111001
10000000000000000001
10000000000000000001
11111111111111111111

Not only is that ridiculously easy to parse, it is also very human-readable.
Topic archived. No new replies allowed.
Pages: 12