Please help! After I run my programme, it does neither breaks, nor any errors or warnings appear and debugger stops in exactly the same moment, before it should approach function - "stworz_inaczej". What's wrong with that? Code below:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
void stworz (int tablica[][6]);
int zablokowany (int tablica[][6], int ind1, int ind2);
int otoczony (int tablica[][6], int ind1, int ind2, int strona);
void stworz_inaczej (int tablica[][6]);
int sprawdz (int tablica[][6]);
void wypisz (int tablica[][6]);
int main()
{
int wybor;
int tablica[6][6];
printf("Ktora metode wybierasz?");
scanf("%d", &wybor);
system("cls");
do{
if (wybor == 1)
stworz(tablica);
if (wybor == 2)
stworz_inaczej(tablica);
printf("------------\n\n");
} while(sprawdz(tablica));
wypisz(tablica);
getchar();
return 0;
}
void stworz (int tablica[][6]){
int i, j;
int ind1, ind2, ind3, ind4;
int kulka = 1;
for (i = 0; i < 6; ++i)
for (j = 0; j < 6; ++j)
tablica[i][j] = 0;
srand(time(NULL));
for (i = 0; i < rand() % 18 + 1; ++i){
do
{
ind1 = rand() % 6;
ind2 = rand() % 6;
ind3 = rand() % 6;
ind4 = rand() % 6;
} while((ind1 == ind3 && ind2 == ind4) || (tablica[ind1][ind2] != 0 || tablica[ind3][ind4] != 0));
tablica[ind1][ind2] = tablica[ind3][ind4] = kulka;
kulka++;
}
}
int sprawdz (int tablica[][6]){
int i, j;
int czy_dobrze_1 = 0;
for (i = 0; i < 6; ++i)
for (j = 0; j < 6; ++j)
if(tablica[i][j] != 0){
if(i - 1 >= 0)
if(tablica[i][j] == tablica[i-1][j] || tablica[i-1][j] == 0)
czy_dobrze_1 = 1;
if(czy_dobrze_1 == 0 && j + 1 < 6)
if(tablica[i][j] == tablica[i][j+1] || tablica[i][j+1] == 0)
czy_dobrze_1 = 1;
if(czy_dobrze_1 == 0 && i + 1 < 6)
if(tablica[i][j] == tablica[i+1][j] || tablica[i+1][j] == 0)
czy_dobrze_1 = 1;
if(czy_dobrze_1 == 0 && j - 1 >= 0)
if(tablica[i][j] == tablica[i][j-1] || tablica[i][j-1] == 0)
czy_dobrze_1 = 1;
}
if (czy_dobrze_1 == 1)
return 0;
else
return 1;
}
int zablokowany (int tablica[][6], int ind1, int ind2){
int czy_wejsc = 1;
if (ind1 - 1 >= 0)
if (tablica[ind1 - 1][ind2] == 0)
czy_wejsc = 0;
if (ind1 + 1 < 6)
if (tablica[ind1 + 1][ind2] == 0)
czy_wejsc = 0;
if (ind2 - 1 >= 0)
if (tablica[ind1][ind2 - 1] == 0)
czy_wejsc = 0;
if (ind2 + 1 < 6)
if (tablica[ind1][ind2 + 1] == 0)
czy_wejsc = 0;
if (czy_wejsc == 0)
return 0;
else if (czy_wejsc == 1)
return 1;
}
int otoczony (int tablica[][6], int ind1, int ind2, int strona){
int czy_wejsc = 1;
if (ind1 - 1 >= 0 && strona != 3)
if (tablica[ind1 - 1][ind2] == 0)
czy_wejsc = 0;
if (ind1 + 1 < 6 && strona != 1)
if (tablica[ind1 + 1][ind2] == 0)
czy_wejsc = 0;
if (ind2 - 1 >= 0 && strona != 2)
if (tablica[ind1][ind2 - 1] == 0)
czy_wejsc = 0;
if (ind2 + 1 < 6 && strona != 4)
if (tablica[ind1][ind2 + 1] == 0)
czy_wejsc = 0;
if (czy_wejsc == 0)
return 0;
else if (czy_wejsc == 1)
return 1;
}
void stworz_inaczej (int tablica[][6]){
int i, j, ile_pol = 0, kulka = 0, gdzie, juz = 0, nastepny, koniec;
for(i = 0; i < 6; ++i)
for(j = 0; j < 6; ++j)
tablica[i][j] = 0;
do{
koniec = 1;
kulka ++;
do{
i = rand() % 6;
j = rand() % 6;
} while(tablica[i][j] != 0 || (zablokowany(tablica, i, j) == 1));
tablica[i][j] = kulka;
ile_pol++;
do{
nastepny = rand() % 2;
if(tablica[i-1][j] == 0 && otoczony(tablica, i-1, j, 1) == 1){
tablica[i-1][j] = kulka;
i--;
ile_pol++;
nastepny = 0;
}
else if(tablica[i][j+1] == 0 && otoczony(tablica, i, j+1, 2) == 1){
tablica[i][j+1] = kulka;
j++;
ile_pol++;
nastepny = 0;
}
else if(tablica[i+1][j] == 0 && otoczony(tablica, i+1, j, 3) == 1){
tablica[i+1][j] = kulka;
i++;
ile_pol++;
nastepny = 0;
}
else if(tablica[i][j-1] == 0 && otoczony(tablica, i, j-1, 4) == 1){
tablica[i][j-1] = kulka;
j--;
ile_pol++;
nastepny = 0;
}
else{
do{
gdzie = rand() % 4 + 1;
switch(gdzie)
{
case 1:
if(i-1 < 0 || tablica[i-1][j] != 0)
break;
else {
tablica[i-1][j] = kulka + 20;
i--;
ile_pol++;
juz = 1;
break;
}
case 2:
if(j+1 > 5 || tablica[i][j+1] != 0)
break;
else {
tablica[i][j+1] = kulka + 20;
j++;
ile_pol++;
juz = 1;
break;
}
case 3:
if(i+1 > 5 || tablica[i+1][j] != 0)
break;
else {
tablica[i+1][j] = kulka + 20;
i++;
ile_pol++;
juz = 1;
break;
}
case 4:
if(j-1 < 0 || tablica[i][j-1] != 0)
break;
else {
tablica[i][j-1] = kulka + 20;
j--;
ile_pol++;
juz = 1;
break;
}
}
} while(juz == 0);
nastepny = rand() % 2;
}
} while (nastepny == 1);
tablica[i][j] = kulka;
for (i = 0; i < 6; ++i)
for (j = 0; j < 6; ++j)
if (zablokowany(tablica, i, j) == 0)
koniec = 0;
} while(ile_pol <= 36 && koniec == 0);
for (i = 0; i < 6; ++i)
for (j = 0; j < 6; ++j)
if (tablica[i][j] >= 20)
tablica[i][j] = 0;
}
void wypisz (int tablica[][6]){
int i, j;
for (i = 0; i<6; ++i){
printf("\n");
for (j = 0; j<6; ++j)
printf("%d\t", tablica[i][j]);
}
}