в общем при запуске программы вылетает ошибка...
При дебаге вылезает сообщение : Acces violation writing location 0xfff48001.
Вот собственно код программы :
#include <conio.h>
#include <string.h>
#include <stdio.h>
typedef struct screen_point{
unsigned char chr;
unsigned char attr;
} screen_line[80];
screen_line* scr;
//Labirint : 0 - Stena, 1 - prohod
char movecost[10][10]={
{0,0,0,0,0,0,0,0,0,0},
{0,1,1,1,1,1,1,0,0,0},
{0,1,0,0,0,0,1,0,0,0},
{0,1,0,1,1,1,1,1,1,0},
{0,1,0,1,1,0,0,0,1,0},
{0,1,0,1,0,0,1,0,1,0},
{0,1,0,1,0,1,1,0,1,0},
{0,1,0,0,0,0,0,0,1,0},
{0,1,1,1,1,1,1,1,1,0},
{0,0,0,0,0,0,0,0,0,0}};
//razmer == razmeru labirinta
unsigned char fillmap[10][10];
struct
{
signed char x,y; // Koordinati v labirinte
}
buf[256];
unsigned char bufp, bufe; //indeksi v buf
int sx, sy, tx, ty; //Hachal\nie i konechnie koordinati puti
//Ochistka ekrana
void clrscr()
{
int i;
for (i = 0; i < 25; i++)
printf("\n");
}
//napechatat' stroku str v koordinatah (x, y) cvetom attr
void writestr(int x, int y, char str[], char attr)
{
int i;
for(i = 0; str[i] != 0; i++, x++)
{
scr[y][x].chr = str[i];
scr[y][x].attr = attr;
}
}
//Risuem Labirint
void draw_maze()
{
int i,j;
for(j = 0; j < 10; j++)
for(i = 0; i < 10; i++)
{
scr[j][i*2].attr = 16*(7-movecost[j][i])+7+8*((i+j)&1);
scr[j][i*2 + 1].attr = 16*(7-movecost[j][i])+7+8*((i+j)&1);
}
scr[sy][sx*2].chr = '[';
scr[sy][sx*2 + 1].chr = ']';
scr[ty][tx*2].chr = '<';
scr[ty][tx*2 + 1].chr = '>';
scr[1][40].attr = 16*(7-1);
writestr(45, 1, "Pustoe mesto", 7);
scr[3][40].attr = 16*(7-0);
writestr(45, 3, "Stena", 7);
scr[5][40].attr = 16*(7-6);
writestr(45, 5, "Boloto", 7);
writestr(40, 7, "[] nachal'naya tochka", 7);
writestr(40, 9, "<> Cel' puti", 7);
}
//Funkcia proveryaet yavlyaetca li predlogaemii put' v tochku bolee korotkim, chem naidenii ranee
//Esli da, to zapominaet tochku v buf.
void push(int x, int y, int n)
{
if(fillmap[y][x] <= n) //esli novii put' ne karoche, to ego v TRASH
return;
fillmap[y][x] = n; //zapominaen novuu dlinu puti
buf[bufe].x = x; //zapominaem tochku
buf[bufe].y = y;
bufe++;
scr[y][x*2].chr = n/10 + 48; //risovanie
scr[y][x*2 + 1].attr = (n%10) + 48;
getch();
}
//Zdes' beretca ocherednaya tochka iz buf i vozvrashaetca 1.
//esli brat' nechego, to vozvrashaetca 0
int pop(int *x, int *y)
{
if(bufp == bufe)
return 0;
*x = buf[bufp].x; //Zapominaem tochki
*y = buf[bufp].y;
bufp++;
return 1;
}
void fill(int sx, int sy, int tx, int ty)
{
int x,y,n,t;
// vnachale fillmap zapolnyaetca max znacheniyami
memset(fillmap, 0xFF, sizeof(fillmap));
bufp = bufe = 0;
push(sx, sy, 0); //Put' v nachal'nuu tochku
while(pop(&x, &y))
{
if((x == tx) && (y == ty))
{
writestr(0, 20, "naiden put' dlinoi ", 15);
scr[20][19].chr = n/10 + 48;
scr[20][20].chr = (n%10) + 48;
break;
}
//n = dlina puti do luboi sosednei kletki
n = fillmap[y][x] + movecost[y][x];
//Perebor 4-h sosednih kletok
if(movecost[y+1][x])
push(x, y+1, n);
if(movecost[y-1][x])
push(x, y-1, n);
if(movecost[y][x+1])
push(x+1, y, n);
if(movecost[y][x-1])
push(x-1, y, n);
}
//libo mi nashli 1 put' i vivalilis' po break
//libo zalili uje vsu kartu
if(fillmap[ty][tx] == 0xFF)
{
writestr(0, 20, "puti ne sushestvuet!!!", 15);
return;
}
else
writestr(0, 20, "zalivka zakonchena, proidemsya po puti!!!", 15);
//Mi nachali zalivku iz (sx, sy), znachit po puti pridetca idti iz (tx, ty)
x = tx;
y = ty;
n = 0xFF;
//poka ne pridem v (sx, sy)
while((x != sx) || (y != sy))
{
scr[y][x*2].attr = 2*16;
scr[y][x*2+1].attr = 2*16;
if(fillmap[y+1][x])
if(fillmap[y-1][x])
if(fillmap[y][x+1])
if(fillmap[y][x-1])
x = tx; y = ty; n = t;
getch();
}
}
void main()
{
//koordinati
int i, sx = 1, sy = 1, tx = 3, ty = 3;
//risuem
scr = (screen_line*)-0xB8000;
clrscr();
draw_maze();
getch();
//Ishen put'
fill(sx, sy, tx, ty);
}