/*
* main.c
*
* Created on: Nov 30, 2012
* Author: mfb
*
* Example input:
* 5 5 2 2 0 0
* y0 . . . . .
* y1 a a a a .
* y2 . . . a .
* y3 . a a a .
* y4 . . . . .
*
* x> 0 1 2 3 4
* I don't know why when I enter these to the program it comes to 4,4 and stops.
*/
#include <stdio.h>
int spx, spy, fx, fy, xsize, ysize;
char *inmap, *check;
int input(void) {
scanf(" %d %d %d %d %d %d", &xsize, &ysize, &fx, &fy, &spx, &spy);
inmap = (char *) malloc(xsize * ysize * sizeof(char));
check = (char *) malloc(xsize * ysize * sizeof(char));
int y;
for (y = 0; y < xsize * ysize; y++)
*(check + y) = 0;
char o;
for (y = 0; y < ysize * xsize; y++) {
scanf(" %c", &o);
if (o == '.')
*(inmap + y) = 1;
else
*(inmap + y) = 0;
}
return 0;
}
int itaw(char *map, int fpx, int fpy) {
if (*(check + fpy * xsize + fpx) == 1)
return 0;
else
*(check + fpy * xsize + fpx) = 1;
if (fpx >= xsize || fpy >= ysize || fpx < 0 || fpy < 0)
return 0;
if (*(map + fpy * xsize + fpx) == 0 || *(map + spy * xsize + spx) == 0)
return 0;
printf("(%d,%d)\n", fpx, fpy);
if (fpx == spx && fpy == spy)
return 1;
return (itaw(map, fpx - 1, fpy) || itaw(map, fpx, fpy - 1)
|| itaw(map, fpx + 1, fpy) || itaw(map, fpx, fpy + 1));
}
int main(void) {
input();
int result = itaw(inmap, fx, fy);
printf("%d\n", result);
return 0;
}
上面是一個找到兩點之間方式的程序。 ''意味着方式和所有其他字符意味着一堵牆。 它主要工作,但當我輸入我上面寫的它返回0.C代碼不起作用
您是否嘗試單步執行調試器中的代碼以查看發生了什麼? –
我猜這是一個學校項目,所以我可以建議這個非常受歡迎的'項目是在幾個小時內完成的,時間是9001 cout陳述'嗎? – Windle
或者像@PaulR所說的真正的調試器;) – Windle