This is an example of what I was suggesting - the setup function:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define R 5
#define C 5
void setup(char grid[R][C]);
void printIt(char grid[R][C]);
int main(void) {
int r, c;
char grid[R][C];
srand(time(NULL));
for(r=0;r<R;r++) {
for(c=0;c<C;c++) {
grid[r][c]=rand() % ('F'-'A') + 'A';
}
printf("\n");
}
printIt(grid);
setup(grid);
printf("\n\n");
printIt(grid);
return 0;
}
void setup(char grid[R][C]) {
int row,col, change=0;
for(row=0;row<R;row++) {
for(col=0;col<C-1;col++) {
while(grid[row][col]==grid[row][col+1]) {
grid[row][(col+1)]++;
change++;
if(grid[row][col+1]>'E') {
grid[row][col+1]='A';
}
}
}
}
printf("\n\nchange: %d\n",change);
}
void printIt(char grid[R][C]) {
int r,c;
for(r=0;r<R;r++) {
for(c=0;c<C;c++)
printf("%c ",grid[r][c]);
putchar('\n');
}
}