hi guys i need help in C coding i did the first half of the problem; however, im suffering with the second half.
I found a method, but the problem its too long and I cant write anymore code.
here is the problem:
if anybody is curious i can tell you my method...
but please somebody give me a hint on how to do this.
make a counter, write an if statement that says if a[row+1][column] == bomb
counter +=1
There's probably an easy way to check all locations around it without too many if statements.
>>8445219
does it look something like that ...
______________________________________________________________
int process(char msweep[12][12],int r,int c,char user_chart[12][12])
{
int i=r,j=c,b=0,k;
char C;
if(msweep[r][c] == '9')
{ k=0;
return k;
}
else
{
if(msweep[i-1][j-1] == '9')
b++;
if(msweep[i-1][j] == '9')
b++;
if(msweep[i-1][j+1] == '9')
b++;
if(msweep[i][j-1] == '9')
b++;
if(msweep[i][j+1] == '9')
b++;
if(msweep[i+1][j-1] == '9')
b++;
if(msweep[i+1][j] == '9')
b++;
if(msweep[i+1][j+1] == '9')
b++;
C = (char)(((int)'0')+b); // to covert int to char;
msweep[r][c] = C;
user_chart[r][c] = C;
>>8445210
I made a minesweeper implementation in C a few years ago, perhaps this should help. https://github.com/AndrewBelt/minesweeper
>>8445228
Please, Please, Please get in the habit of using readable variable names
>>8445228
yeah something like that, it's a bit messy but it's the simplest way. You could also use two for loops to scan the "square" around each cell.
C is a pretty bare bone language, so I doubt there's a high level function you can use to count the number of true statements in a list. You could build one yourself but it'd take more time than the straight forward approach.
>>8445271
>https://github.com/AndrewBelt/minesweeper
i truly appreciate your help... but i think i found the shorter method... i can't believe i was about to brute force my way through every possibility...
here is what im using:
for(o = 0; o < m; o++) {
for(u = 0; u < n; u++) {
if (array[o][u] /*<p*/= 1){printf(" * ", array[o][u]);}
else{
// Check for mine below
if(array[o+1][u] == '*')
mine_count++;
// Check for mine to the right.
if(array[o][u+1] == '*')
mine_count++;
// Check for mine diagonal-dright.
if(array[o+1][u+1] == '*')
mine_count++;
// Check for mine diagonal-dleft
if(array[o+1][u-1] == '*')
mine_count++;
// Check for mine to the left
if(array[o][u-1] == '*')
mine_count++;
// Check for mine above
if(array[o-1][u] == '*')
mine_count++;
// Check for mine diagonal-uright
if(array[o-1][u+1] == '*')
mine_count++;
// Check for mine diagonal-uleft
if(array[o-1][u-1] == '*')
mine_count++;
printf("%d", main_count);
}
}
}
>>8445317
sorry is it clearer now.
also does anybody know how to put a int variable in an array...
i want to printf(mine_cont , array[o][u]);
but mine_count is a variable ???
>>8445271
>posting your real name on le 4chinz
>>8445331
ya it wasn't the smartest thing ... but since he was kind i didn't bring it up hoping no one would notice...
to be honest with you there are to many andrew belts anyways ... you would have to really be motivated to find him.
>>8445332
I'm not one of those retards who doxxes people for the fun of it, but I just wanted to bring it to his attention
>>8445340
im sorry to bug you but can you tell me how to print a variable in an array...
i want to printf(mine_cont , array[o][u]);
but mine_count is a variable ???
I mean, you can have my name. It's not like I'm a 13 year old girl posting to /g/.
>>8445349
dont worry about man ...
but can you tell me how to do that:
i want to printf(mine_cont , array[o][u]);
but mine_count is a variable ???
>>8445351
printf("%d/n", mine_count);
If it's an integer.
>>8445373
but i want it to be a number within the array
something similar to this :
{printf(" * ", array[o][u]);}
>>8445345
For one, the first argument to printf MUST be a string. All other arguments are various variable or constants to substitute into the string whereever there is the proper % specifier.
I'm assuming mine_cont and array[o][u] are both integers, so you'd use something like:
printf("%d,%d\n", mine_cont, array[o][u]);
%d is the specifier to replace with a variable converted to integer representation, \n means newline.
So if mine_cont = 5 and array[o][u] = 7, it will output
5,7.
>>8445377
I'm not sure I understand what you mean. Do you just want to print a value that's stored in the array? Then you can just use array[o][u], provided o and u are appropriately defined.