[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Coding in C (Desperate need of help)

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 16
Thread images: 2

File: Capture.png (205KB, 598x852px) Image search: [Google]
Capture.png
205KB, 598x852px
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
>>
File: 1466348276026.jpg (24KB, 551x480px) Image search: [Google]
1466348276026.jpg
24KB, 551x480px
>>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.
Thread posts: 16
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.