Problem with "Segmentation fault (core dumped)"

Hello

I have a little problem with my program, I have a problem with "Segmentation fault (core dumped)", My algorithm search a way in labyrinth, but i have problem with allocate memory. I don't have any idea to fix this. Can I ask someone to help me with this? or give me a little suggestion what's is wrong? Sorry for my English i still learning ;)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 int steps=-1;
	int *il;
	il=(int *) malloc (((m)*(n))*sizeof(int));
	bool c = true;
	*il = x;// x is start point (int = -5 is entrance and exit of labyrinth (something like start and meta) ;)
	for (int i=1; i < (m*n); *(il+i)=-3,i++);
	int check=0;
	int z=0;
	bool exit = true; // don't worry about this.
	while ( c == true) {
		int d = *(il+z);
		if ( *(tab + d) == -5 ) {
			check++;
		}
		if (check == 2 ) {
			 c = false;
		}
		if ( *(tab+d) == -3) {
			exit  = false;
			c = false;
		}		
		if ( *(tab+d+1) != -1 ) {
			*(il++) = d+1;
		} 
		if ( *(tab+d-1) != -1){
			*(il++) = d-1; 
		}
		 if ( *(tab+d+n+2 ) != -1){
			*(il++) = d+n+2;
		}
		if ( *(tab + d  - n - 2) != -1){
			*(il++) = d-n-2;
		} 
		il++;
		z++;
		steps++;
	} 
I'll help to debug when I get more free time.
In the meantime, please do the following generic procedures for debugging:

1, use a debugger (e.g. gdb) or even cout to locate when things start to go wrong.
2, once you find the place, try to display program state. i.e. variables. In some complex cases, you may want to use dumpbin or objdump to see what's going on exactly in your program's memory segments.
3, once you find the mistake, correct it and retest

Last but not least, please don't leave out the function prototype.
Thanks for help ;) I find a bug, i use other method to do this algorithm, and that it's work :) Thank you ;)
Topic archived. No new replies allowed.