I am a beginner at C++ and I would like to hear your opinion about my code. I don't think it's necessary to desrcribe what the program really does, because it works fine, although there are some special occasions that can result in a crash. Could you take a look at my code and tell me what I could improve?
using namespace std;
void explode(char* str, int* output){
char temp[20];
int tr = 0;
int ot = 0;
for(int x = 0;x<strlen(str);x++){
if(str[x] != *" "){
temp[tr++] = str[x];
}
else{
temp[tr] = '\0';
tr= 0 ;
sscanf(temp, "%d", &output[ot++]);
}
}
temp[tr] = '\0';
tr= 0 ;
sscanf(temp, "%d", &output[ot++]);
}
int main(int argc, char** argv) {
int n = 0;
cin >> n;
int* nulaX[n];
int* nulaY[n];
cin.ignore(256, '\n');
int* r[n];
int* stepsAmmount = new int[n];
int* steps[n];
short* pole[n][300];
for(int wH = 0;wH<n;wH++){
r[wH] = new int;
nulaX[wH] = new int;
nulaY[wH] = new int;
cin >> *r[wH];
cin.ignore(256, '\n');
int* gg = new int[*r[wH]];
char* input = new char[*r[wH]];
for(int x = 0;x<*r[wH];x++){
cin.getline(input,250);
pole[wH][x] = new short[*r[wH]];
explode(input, gg);
for(int y = 0;y<*r[wH];y++){
pole[wH][x][y] = gg[y];
if(pole[wH][x][y] == 0){
*nulaX[wH] = x;
*nulaY[wH] = y;
}
}
}
cin >> stepsAmmount[wH];
cin.ignore(256, '\n');
steps[wH] = new int[stepsAmmount[wH]];
char* tempC = new char[1000];
cin.getline(tempC,250);
explode(tempC, steps[wH]);
}
int step, tempX, tempY;
for(int wH = 0;wH < n;wH++){
for(int x = 0;x<stepsAmmount[wH];x++){
step = steps[wH][x];
if(*nulaX[wH]-1 >= 0 && pole[wH][*nulaX[wH]-1][*nulaY[wH]] == step){
tempX = *nulaX[wH]-1;
tempY = *nulaY[wH];
}
else if(*nulaX[wH]+1 < *r[wH] && pole[wH][*nulaX[wH]+1][*nulaY[wH]] == step){
tempX = *nulaX[wH]+1;
tempY = *nulaY[wH];
}
else if(*nulaY[wH]-1 >= 0 && pole[wH][*nulaX[wH]][*nulaY[wH]-1] == step) {
tempX = *nulaX[wH];
tempY = *nulaY[wH]-1;
}
else if(*nulaY[wH]+1 < *r[wH] && pole[wH][*nulaX[wH]][*nulaY[wH]+1] == step){
tempX = *nulaX[wH];
tempY = *nulaY[wH]+1;
}
else{
cout << "Pokus o utok" << endl;
return 0;
}
pole[wH][*nulaX[wH]][*nulaY[wH]] = pole[wH][tempX][tempY];
pole[wH][tempX][tempY] = 0;
*nulaX[wH] = tempX;
*nulaY[wH] = tempY;
}
int m = 0;
bool result = true;
for(int x = 0;x<*r[wH];x++){
for(int y = 0;y<*r[wH];y++){
if(pole[wH][x][y] == 0){
continue;
}
else if(++m != pole[wH][x][y]){
x = *r[wH];
result = false;
break;
}
}
}
if(result == true){
cout << "Prihlaseny do systemu" << endl;
}
else{
cout << "Cas vyprsal" << endl;
}
}
}