0

Possible Duplicate:
What is the function to replace string in C?

I'm designing a game in C and I've set up my "board" with a 10x10 2D array filled with characters. There are only four characters in the board, and they've been randomly generated.

Anyone got an idea of how to search for a 3 in a row within say board[1]?

Row 0: a b b b c d a a c d

So there's a match of 'bbb' in there. How do traverse my search in such a way that I get to remove all 'b's, switch them to spaces, and then add them up to a score?

The result would look like this: (' ' is the replacement)

Row 0: a       c d a a c d

And after that, I also need to check for lines of 4 and 5. Any help would be appreciated. :)

EDIT: Adding a sample of how i'm trying to solve this.

char c[10][10];
int start; //where i would start deleting
int end; //where i would stop deleting from the rows/columns

//REMOVE LINES OF 3/4/5          
for(i = 0; i < 10; i++) { //BY ROWS
       tempChar = c[i][0];
       start = 0;

       for(j = 1; j < 10; j++) { //EACH ELEMENT IN THE ROW
           if(tempChar == c[i][j] && tempChar != ' ') {
             counter++; //found one more next to it
             end = j; //end of the 3/4/5 in a row
           }
       }
 }
Community
  • 1
  • 1
thundrshock
  • 83
  • 1
  • 6
  • what have you tried? What are you having trouble with? Show us what you have so far. – twain249 Mar 25 '12 at 17:55
  • please post the definition of `board` and how you've initialised it. There are several ways to do this. You are familiar with your code, but we are not, so please make it easy for us to help. – gbulmer Mar 25 '12 at 17:55
  • edited my code. been trying to work out `if` statements of groups of three `c[i][j] == c[i][j+1] == c[i][j+2]`, but there will be instances of out of bounds in the array. and it doesn't pick it up so well. – thundrshock Mar 25 '12 at 18:32

0 Answers0