I'm currently having difficulties on selecting and marking a value that had been on selected on a 2d array.
Example: Before selecting the value the array should look like this.
Code:
# # # # # # # # # # # #
# 1 2 #
# 4 #
# 6 2 8 #
# #
# 1 3 5 #
# #
# 3 6 #
# 4 5 #
# 7 #
# 7 8 #
# # # # # # # # # # # #
Example:After Selecting the value the array should look like this, assume the user select number 1 as the value.
Code:
# # # # # # # # # # # #
# [1] 9 2 #
# 4 #
# 6 2 8 #
# #
# 1 3 5 #
# #
# 3 6 #
# 4 5 #
# 9 7 #
# 7 8 #
# # # # # # # # # # # #
My current code:
Code:
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
void print_array(int arr[12][12], int ar[144]){
int i,j,m=0;
for(i=0;i<38;i++)
{
printf("#");
}
printf("\n");
for(i=0;i<12;i++)
{
for(j=0;j<14;j++)
{
if(j==0)
{
printf("#");
}
else if(j==13)
{
printf("#");
}
else
{
arr[i][j-1] = ar[m++];
if(arr[i][j-1] == 0)
{
printf(" ");
}
else
{
printf(" %d " , arr[i][j-1]);
}
}
}
printf("\n");
}
for(i=0;i<38;i++)
{
printf("#");
}
printf("\n");
}
void shuffle(int arr[12][12], int ar[144]){
int t,j,i;
srand ( time(NULL) );
for(i=144-1;i>0;i--)
{
j=rand() % (i+1);
t=ar[j];
ar[j] = ar[i];
ar[i] = t;
}
}
//error the whole selectnumber seems to have problem
void selectnumber(int arr[12][12], int ar[144], int *num, int *x, int *y)
{
int i, j, test=0;
int temp;
printf("please select a number from 1-8:\n");
fflush(stdin);
scanf("%d", &temp);
arr[*y][*x]=' ';
arr[*y+1][*x]=' ';
for (j=0; j<=12; j++)
{
for (i=0; i<=12; i++)
{
if(arr[j][i]==temp && test==0)
{
*y = j;
*x = i;
test = 1;
}
}
}
arr[*y][*x]='-';
arr[*y+1][*x]='-';
*num=temp;
}
int main()
{
int array[12][12]={0};
int randvalues[144]={1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8};
int gx,gy;
int ginput;
shuffle(array,randvalues);
print_array(array,randvalues);
selectnumber(array, randvalues, &ginput, &gy, &gx);
return 0;
}
Since my array consist two types of array therefore i'm very confused on how to do it, please kindly help me