15 Puzzle Program, stuck on up left right down commands - c

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (void){
//Function used to set up your game board
int disp[4][4];
int i, j;
int game_over = 0;
for(i = 0; i < 4; i++) {
for(j = 0;j < 4; j++) {
printf("Enter a value from 1 - 15 for %d %d: ", i, j);
scanf("%d", &disp[i][j]);
}
}
//Function used to display the game board
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
printf(" _ ");
else if (disp[i][j] < 10)
printf(" %d ",disp[i][j]);
else
printf("%d ",disp[i][j]);
}
}
// Function to show where cursor is
for(i = 0; i < 4; i++){
printf("\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
printf("");
}
}
//Skeleton to function to controller
do{
char move[10];
printf("Enter a move: ");
scanf("%s", move);
if (strcmp("up", move) == 0){
for(i = 0; i < 4; i++){
printf("");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (i >= 1){
int temp = disp[i][j];
disp[i][j] = disp[i - 1][j];
disp[i - 1][j] = temp;
}
else {
printf("Invalid move!");
}
}
}
}
else if (strcmp("Up", move) == 0){
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (i > 1){
int temp = disp[i][j];
disp[i][j] = disp[i - 1][j];
disp[i - 1][j] = temp;
}
else {
printf("Invalid move!");
}
}
}
}
else if (strcmp("UP", move) == 0){
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (i > 1){
int temp = disp[i][j];
disp[i][j] = disp[i - 1][j];
disp[i - 1][j] = temp;
}
else {
printf("Invalid move!");
}
}
}
}
else if (strcmp("down", move) == 0){
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (i < 4){
int temp = disp[i][j];
disp[i][j] = disp[i + 1][j];
disp[i + 1][j] = temp;
}
else {
printf("Invalid move!");
}
}
}
}
else if (strcmp("Down", move) == 0){
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (i < 4){
int temp = disp[i][j];
disp[i][j] = disp[i + 1][j];
disp[i + 1][j] = temp;
}
else {
printf("Invalid move!");
}
}
}
}
else if (strcmp("DOWN", move) == 0){
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (i < 4){
int temp = disp[i][j];
disp[i][j] = disp[i + 1][j];
disp[i + 1][j] = temp;
}
else {
printf("Invalid move!");
}
}
}
}
else if (strcmp("left", move) == 0){
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (j >= 1){
int temp = disp[i][j];
disp[i][j] = disp[i][j - 1];
disp[i][j - 1] = temp;
}
else {
printf("Invalid move!");
}
}
}
}
else if (strcmp("Left", move) == 0){
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (i > 1){
int temp = disp[i][j];
disp[i][j] = disp[i][j + 1];
disp[i][j + 1] = temp;
}
else {
printf("Invalid move!");
}
}
}
}
else if (strcmp("LEFT", move) == 0){
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (i > 1){
int temp = disp[i][j];
disp[i][j] = disp[i][j + 1];
disp[i][j + 1] = temp;
}
else {
printf("Invalid move!");
}
}
}
}
else if (strcmp("right", move) == 0){
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (j <= 4){
int temp = disp[i][j];
disp[i][j] = disp[i][j + 1];
disp[i][j + 1] = temp;
}
else {
printf("Invalid move!");
}
}
}
}
else if (strcmp("Right", move) == 0){
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (i > 4){
int temp = disp[i][j];
disp[i][j] = disp[i][j - 1];
disp[i][j - 1] = temp;
}
else {
printf("Invalid move!");
}
}
}
}
else if (strcmp("RIGHT", move) == 0){
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (i > 4){
int temp = disp[i][j];
disp[i][j] = disp[i][j - 1];
disp[i][j - 1] = temp;
}
else {
printf("Invalid move!");
}
}
}
}
else
printf("Invalid Move!");
//Update the board function
for(i = 0; i < 4; i++){
printf("\n\n");
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
printf(" _ ");
else if (disp[i][j] < 10)
printf(" %d ",disp[i][j]);
else
printf("%d ",disp[i][j]);
}
}
}
while (game_over == 0);
return 0;
}
I am having trouble making the cursor go right or down? I can go left and up, but not the other two. I'm not looking for someone to answer the entire program its just I have been stuck on this for hours and every other code I look at sees similar to mine.I can get it to correctly do up and left but right and down cause a problem and not sure why.

The bug is the checking logic is wrong and the bad practice you followed is lots of repetitive code.
Well I have boiled the code to something simple.
...
else if (strcmp("down", move) == 0 || strcmp("Down", move) == 0 || strcmp("DOWN", move) == 0){
int d = 0;
for(i = 0; i < 4; i++){
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if (i+1 < 4){ // <--- notice the change
int temp = disp[i][j];
disp[i][j] = disp[i + 1][j];
disp[i + 1][j] = temp;
d = 1;
break; // <-- and this
}
else {
printf("%s","Invalid move!");
}
}
if( d == 1)
break;
}
}
else if (strcmp("right", move) == 0 || strcmp("Right", move) == 0 || strcmp("RIGHT", move) == 0){
for(i = 0; i < 4; i++){
for(j = 0; j < 4; j++){
if (disp[i][j] == -1)
if ( j+1 < 4){ // <--- notice the change
int temp = disp[i][j];
disp[i][j] = disp[i][j + 1];
disp[i][j + 1] = temp;
break; // <-- and this
}
else {
printf("%s","Invalid move!");
}
}
}
}
...
You can check that there is a break statement in case of down and right. The reason is, when you swap -1 to the right or down then you will meet up again in the loop iteration.
So without the break the result would be
_ 1 2 3
4 5 6 7
8 9 1 2
3 4 5 6
>>> right
1 2 3 _
4 5 6 7
8 9 1 2
3 4 5 6
Another thing is don't repeat code. The readability is worse when you do that. Maintaining the code is even harder. Even better here you can write swap() logic and use it. And also the movement of the tiles can also be done with another function.
Tricky downlogic (Edit-1).
In case of downlogic the simple breaking up the loop wont work because in case you do that there will be a chance that in next iteration it will again get -1 and try to swap it with next number.

Related

Why when I try to run this code online it always generates runtime error/run error. but when I run it in command prompt it works [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed yesterday.
Improve this question
This code is a program that will move the index position of several names according to the size of the toga that each participant has, and according to the name that the user wants to change.
#include <stdio.h>
#include <string.h>
typedef struct
{
char nama[100];
char ukuran[100];
} toga;
int main()
{
int n, m;
scanf("%d%d", &n, &m);
toga matriks[n][m];
int jumlah[n][m];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
scanf("%s%s", &matriks[i][j].nama, &matriks[i][j].ukuran);
if(strcmp(matriks[i][j].ukuran, "XS") == 0)
{
jumlah[i][j] = 32;
}
else if(strcmp(matriks[i][j].ukuran, "S") == 0)
{
jumlah[i][j] = 36;
}
else if(strcmp(matriks[i][j].ukuran, "M") == 0)
{
jumlah[i][j] = 37;
}
else if(strcmp(matriks[i][j].ukuran, "L") == 0)
{
jumlah[i][j] = 38;
}
else if(strcmp(matriks[i][j].ukuran, "XL") == 0)
{
jumlah[i][j] = 40;
}
else if(strcmp(matriks[i][j].ukuran, "XXL") == 0)
{
jumlah[i][j] = 42;
}
else if(strcmp(matriks[i][j].ukuran, "XXXL") == 0)
{
jumlah[i][j] = 45;
}
}
}
maybe this part is the problem?
toga ditukar1[50][50];
toga ditukar2[50][50];
int cek2 = 0;
for (int i = 0; i < 50; i++)
{
for(int j = 0; j < 1; j++)
{
scanf("%s", &ditukar1[i][0].nama);
if(strcmp(ditukar1[i][0].nama, "Selesai") == 0)
{
j = 1;
i = 50;
}
else
{
scanf("%s ", &ditukar1[i][1].nama);
// cek1++;
}
}
cek2++;
}
cek2 -= 1;
// printf("ini cek1 : %d\n", cek1);
// printf("ini cek2 : %d\n", cek2);
toga matriks_baru[m][n];
for (int i = 0, a = 0; i < m && a < m; i++, a++)
{
for (int j = 0, b = 0; j < n && b < n; j++, b++)
{
strcpy(matriks_baru[a][b].nama ,matriks[j][i].nama);
}
}
int max_len[m];
max_len[0] = 0;
int terpanjang[m];
int a = 0;
for (int i = 0; i < m; i++)
{
max_len[a] = 0;
for (int j = 0; j < n; j++)
{
if(strlen(matriks_baru[i][j].nama) > max_len[a])
{
max_len[a] = strlen(matriks_baru[i][j].nama);
}
}
a++;
}
printf("Posisi awal :\n");
for(int i = 0; i < n; i++)
{
a = 0;
for(int j = 0; j < m; j++)
{
if(j != m-1)
{
printf("%s ", matriks[i][j].nama);
}
else
{
printf("%s", matriks[i][j].nama);
}
if(j != m-1)
{
for(int k = 0; k < (max_len[a]) - (strlen(matriks[i][j].nama)); k++)
{
printf(" ");
}
}
a++;
}
printf("\n");
}
printf("\n");
int baris1, baris2;
int kolom1, kolom2;
int k = 0;
int l = 0;
maybe this part is the problem?
here I will check whether the name entered by the user whose index you want to exchange is in the matrix
for(int l = 0; l < cek2; l++)
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
for(int a = 0; a < n; a++)
{
for(int b = 0; b < m; b++)
{
if(strcmp(ditukar1[l][0].nama, matriks[i][j].nama) == 0)
{
baris1 = i;
kolom1 = j;
if(strcmp(ditukar1[l][1].nama, matriks[a][b].nama) == 0)
{
// printf("%d\n", l);
baris2 = a;
kolom2 = b;
if(baris1 < baris2)
{
char temp1[] = "0";
int temp2 = 0;
if(jumlah[baris1][kolom1] > jumlah[baris2][kolom2])
{
temp2 = jumlah[baris1][kolom1];
jumlah[baris1][kolom1] = jumlah[baris2][kolom2];
jumlah[baris2][kolom2] = temp2;
strcpy(temp1, matriks[baris2][kolom2].nama);
strcpy(matriks[baris2][kolom2].nama, matriks[baris1][kolom1].nama);
strcpy(matriks[baris1][kolom1].nama, temp1);
}
}
else if(baris1 > baris2)
{
char temp1[] = "0";
int temp2 = 0;
if(jumlah[baris2][kolom2] > jumlah[baris1][kolom1])
{
temp2 = jumlah[baris2][kolom2];
jumlah[baris2][kolom2] = jumlah[baris1][kolom1];
jumlah[baris1][kolom1] = temp2;
strcpy(temp1, matriks[baris1][kolom1].nama);
strcpy(matriks[baris1][kolom1].nama, matriks[baris2][kolom2].nama);
strcpy(matriks[baris2][kolom2].nama, temp1);
}
}
}
}
}
}
}
}
}
for (int i = 0, a= 0; i < m && a < m; i++, a++)
{
for (int j = 0, b = 0; j < n && b < n; j++, b++)
{
strcpy(matriks_baru[a][b].nama ,matriks[j][i].nama);
}
}
int max_len2[m];
max_len2[0] = 0;
int s = 0;
for (int i = 0; i < m; i++)
{
max_len2[s] = 0;
for (int j = 0; j < n; j++)
{
if(strlen(matriks_baru[i][j].nama) > max_len2[s])
{
max_len2[s] = strlen(matriks_baru[i][j].nama);
}
}
s++;
}
printf("Posisi akhir :\n");
for(int i = 0; i < n; i++)
{
s = 0;
for(int j = 0; j < m; j++)
{
if(j != m-1)
{
printf("%s ", matriks[i][j].nama);
}
else
{
printf("%s", matriks[i][j].nama);
}
if(j != m-1)
{
for(int k = 0; k < (max_len2[s]) - (strlen(matriks[i][j].nama)); k++)
{
printf(" ");
}
}
s++;
}printf("\n");
}
return 0;
}

how to get different array in for loop every time?

#include<stdio.h>
#include<time.h>
int main(void)
{
srand(time(NULL));
int answer;
int treatment = rand() % 4;
printf("###발모제 찾기###\n\n");
int cntShowBottle = 0;
int prevCntShowBottle = 0;
int ptr[4] = { 0,0,0,0 };
int bottle[4] = { 0, 0, 0, 0 };
int isincluded = 0;
for (int i = 1; i <= 3; i++)
{
do {
cntShowBottle = rand() % 2 + 2;
} while (cntShowBottle == prevCntShowBottle);
prevCntShowBottle = cntShowBottle;
printf(" %d 번째 시도 : ", i);
for (int j = 0; j < cntShowBottle; j++)
{
int randBottle = rand() % 4;
if (bottle[randBottle] == 0)
{
bottle[randBottle] = 1;
if (randBottle == treatment)
{
isincluded = 1;
}
}
else
{
j--;
}
}
}
if (bottle[0] == ptr[0] && bottle[1] == ptr[1] && bottle[2] == ptr[2] && bottle[3] == ptr[3])
{
int bottle[4] = { 0,0,0,0 };
for (int j = 0; j < cntShowBottle; j++)
{
int randBottle = rand() % 4;
if (bottle[randBottle] == 0)
{
bottle[randBottle] = 1;
if (randBottle == treatment)
{
isincluded = 1;
}
}
else
{
j--;
}
}
}
else
{
return 0;
}
for (int i = 0; i < 4; i++)
{
ptr[i] = bottle[i];
}
for (int k = 0; k < 4; k++)
{
if (bottle[k] == 1)
printf("%d ", k + 1);
}
printf("번 물약을 머리에 바릅니다.\n\n");
if (isincluded == 1)
{
printf("성공!\n");
}
else
{
printf("실패...\n");
}
printf("\n ...계속 하려면 아무키나 누르세요...");
getchar(0);
printf("\n\n발모제는 몇 번? : ");
scanf_s("%d", &answer);
if (answer == treatment+1)
{
printf("\n 정답! \n");
}
else
{
printf("\n 실패! \n 정답은 %d 였습니다.\n", treatment+1);
}
return 0;
}
in this loop, for (int j = 0; j < cntShowBottle; j++), 'bottle' array will be [0,1,1,1] or [1,1,0,0] etc. In this loop, how to get different array without overlapping(like [0,1,1,0] and again [0,1,1,0])?? I tried comparing each elements, if it takes overlapping array, makes 'bottle' array again. but it didn't run properly. please help..

Counting number of neighbors Conway's Game of Life

I have an error somewhere in this code.
The number of neighbors is not being counted correctly, as per my understanding. The neighbors function is probably where the issue is. My field variable is a 12x12 char array, the '#' is an alive cell and '-' is a dead one.
I am relatively new to programming and would appreciate some help with this.
int neighbors(int l, int c)
{
int num = 0;
for (int i = -1; i < 2; i++)
{
for (int j = -1; j < 2; j++)
{
if ((l+i < 0 || l+i > 12) && (c+j < 0 || c+j > 12))
{
continue;
}
else if ((i != 0 || j != 0) && field[(l + i)][(c + j)] == '#')
{
num++;
}
}
}
return num;
}
//game logic
void logic()
{
char temp[12][12];
for (int i = 0; i < 12; i++)
{
for (int j = 0; j < 12; j++)
{
temp[i][j] = field[i][j];
}
}
for (int i = 0; i < 12; i++)
{
for (int j = 0; j < 12; j++)
{
if (field[i][j] == '#')
{
if (neighbors(i, j) < 1 || neighbors(i, j) > 3)
{
temp[i][j] = '-';
}
else
{
temp[i][j] = '#';
}
}
if (field[i][j] = '-')
{
if (neighbors(i, j) == 3)
{
temp[i][j] = '#';
}
else
{
temp[i][j] = '-';
}
}
field[i][j] = temp[i][j];
}
}
}
If the array has dimensions 12x12, the maximum index value is 11, hence the test if ((l+i < 0 || l+i > 12) && (c+j < 0 || c+j > 12)) is incorrect. It should be:
if (l+i < 0 || l+i >= 12 || c+j < 0 || c+j >= 12)
continue;
Another major problem is you update field[i][j] = temp[i][j]; inside the update loop: this corrupts the computation for the neighbors of the adjacent cells. You should first compute the whole temp array and update field in a subsequent loop, or with a single call to memcpy().
Furthermore, the standard rules for Conway's Game of Life are somewhat different from your implementation: if (neighbors(i, j) < 1 || neighbors(i, j) > 3) keeps a cell with a single neighbour alive whereas under the standard rules it should die. Change this test to:
if (neighbors(i, j) < 2 || neighbors(i, j) > 3)
temp[i][j] = '-';
Here is a simplified version:
int neighbors(int l, int c) {
int num = 0;
for (int i = -1; i < 2; i++) {
for (int j = -1; j < 2; j++) {
if (l+i >= 0 && l+i < 12 && c+j >= 0 && c+j < 12
&& (i != 0 || j != 0) && field[l+i][c+j] == '#') {
num++;
}
}
}
return num;
}
//game logic
void logic() {
char temp[12][12];
for (int i = 0; i < 12; i++) {
for (int j = 0; j < 12; j++) {
temp[i][j] = field[i][j];
}
}
for (int i = 0; i < 12; i++) {
for (int j = 0; j < 12; j++) {
int nb = neighbors(i, j);
if (nb < 2 || nb > 3) {
temp[i][j] = '-';
} else
if (nb == 3) {
temp[i][j] = '#';
}
}
}
for (int i = 0; i < 12; i++) {
for (int j = 0; j < 12; j++) {
field[i][j] = temp[i][j];
}
}
}

How to make the program see the new matrix I created?

I want to realize the matrix multiplication using Strassen method. Since my input matrix will not be 2^n *2^n all the time, for example, it could be 3*3 matrix, I need to fill the edge area with 0. But I came across a problem when I create new matrix A_new[][] for A[][], B_new[][] for B[][]. I can successfully generate the A_new[][] and B_new[][] for both square(2*2, etc.) or (3*3,etc.). But when I want to further use A_new[][] and B_new[][], which I created before, the code outside the "if" statement couldn't see it.
Is there some ways that I could make the code which is outside the "if" statement see it and process it?
Here are my code.
void strassen(int A[][N], int B[][N], int C[][N]) {
if (N == 1) {
C[0][0] = A[0][0] * B[0][0];
}
if (N > 1 && N % 2 != 0) {
int A_new[N + 1][N + 1];
int B_new[N + 1][N + 1];
int i, j;
for (i = 0; i < N + 1; i++) {
if (i == N) {
for (j = 0; j < N + 1; j++) {
A_new[i][j] = 0;
B_new[i][j] = 0;
}
} else {
for (j = 0; j < N + 1; j++) {
if (j == N) {
A_new[i][j] = 0;
B_new[i][j] = 0;
} else {
A_new[i][j] = A[i][j];
B_new[i][j] = B[i][j];
}
}
}
}
for (i = 0; i < N + 1; i++) {
for (j = 0; j < N + 1; j++) {
C[i][j] = 0;
}
}
} else {
int i, j;
int A_new[N][N];
int B_new[N][N];
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
A_new[i][j] = A[i][j];
}
}
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
B_new[i][j] = B[i][j];
}
}
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
C[i][j] = 0;
}
}
}
if you move int A_new[N + 1][N + 1]; and int B_new[N + 1][N + 1]; before the if you can use A and B in the two branches of the if without problem, and they are available after the if too of course. You do not use all the cells in the else branch but that has no consequences
int A_new[N + 1][N + 1];
int B_new[N + 1][N + 1];
if (N > 1 && N % 2 != 0) {
int i, j;
for (i = 0; i < N + 1; i++) {
if (i == N) {
for (j = 0; j < N + 1; j++) {
A_new[i][j] = 0;
B_new[i][j] = 0;
}
} else {
for (j = 0; j < N + 1; j++) {
if (j == N) {
A_new[i][j] = 0;
B_new[i][j] = 0;
} else {
A_new[i][j] = A[i][j];
B_new[i][j] = B[i][j];
}
}
}
}
for (i = 0; i < N + 1; i++) {
for (j = 0; j < N + 1; j++) {
C[i][j] = 0;
}
}
} else {
int i, j;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
A_new[i][j] = A[i][j];
}
}
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
B_new[i][j] = B[i][j];
}
}
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
C[i][j] = 0;
}
}
}
As chux says in a remark you missed an else (or you just return if N == 1 ?) and the code can be
int A_new[N + 1][N + 1];
int B_new[N + 1][N + 1];
if (N == 1) {
C[0][0] = A[0][0] * B[0][0];
}
else if (N > 1 && N % 2 != 0) {
int i, j;
for (i = 0; i < N + 1; i++) {
if (i == N) {
for (j = 0; j < N + 1; j++) {
A_new[i][j] = 0;
B_new[i][j] = 0;
}
} else {
for (j = 0; j < N + 1; j++) {
if (j == N) {
A_new[i][j] = 0;
B_new[i][j] = 0;
} else {
A_new[i][j] = A[i][j];
B_new[i][j] = B[i][j];
}
}
}
}
for (i = 0; i < N + 1; i++) {
for (j = 0; j < N + 1; j++) {
C[i][j] = 0;
}
}
} else {
int i, j;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
A_new[i][j] = A[i][j];
}
}
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
B_new[i][j] = B[i][j];
}
}
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
C[i][j] = 0;
}
}
}

by using scanf stopped working

here is my code a part of a project when i initialize CHAR_1,CHAR_2 it works but when i read them by scanf it stopped working.
int repair_beta(char beta[11][11])
{
int i = 0, j = 0;
int count = 0, n = 0;
int fail = 0;
for(i = 1; i < 11; i++)
{
for(j = 1; j < 11; j++)
{
if(beta[i][j] == stronghold)
{
count++;
}
}
}
if(count == 4)
{
return 1;
}
else if(count < 4)
{
char CHAR_1 = 'A', CHAR_2 = '5';
for(n = 0; n < 3; n++)
{
printf("\n\t\t <<choose to repair>>\n\t\t\t ");
scanf("%c", &CHAR_1);
scanf("\n%c", &CHAR_2);
for(i = 1; i < 11; i ++)
{
if(CHAR_1 == 'A' + i - 1)
{
break;
}
}
for(j = 1; j < 11; j++)
{
if(CHAR_2 == '0' + j - 1)
{
break;
}
}
if(beta[i][j] == LAND || beta[i][j] == land)
{
beta[i][j] = stronghold;
prize_beta--;
printf("\n\t\t\t <<repaired>>");
printf("\n****************************************************************************\n");
return 1;
}
else
{
fail++;
}
}
if(fail == 3)
{
printf("\n\t\t <<you failed to repair>>");
prize_beta;
printf("\n****************************************************************************\n");
}
}
}
it is my firs time i use stackoverflow so excuse me if i ask my question in bad way.

Resources