so I decided to write a boggle board generator, and it doesn't exactly work.
the problem is that it prints a 4x3 grid... what....
also in the place where i have used[thenum] check, used[thenum] is always 1 even at the very beginning of the program. i initialize it to all zeros.
any ideas?
ps don't bug me about using rand() this is just a PoC
also: i use mac 10.8 xcode
Code:
the problem is that it prints a 4x3 grid... what....
also in the place where i have used[thenum] check, used[thenum] is always 1 even at the very beginning of the program. i initialize it to all zeros.
any ideas?
ps don't bug me about using rand() this is just a PoC
also: i use mac 10.8 xcode
Code:
//
// main.c
// boggle
//
// Created by Ethan ________ on 8/11/13.
// Copyright (c) 2013 Ethan _________. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, const char * argv[])
{
char *cubes[16] = {
"FORIXB", "MOqABJ", "GURILW", "SETUPL",
"CMPDAE", "ACITAO", "SLCRAE", "ROMASH",
"NODESW", "HEFIYE", "ONUDTK", "TEVIGN",
"ANEDVZ", "PINESH", "ABILYT", "GKYLEU" };
int i;
int used[16] =
{0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0};
int thenum;
/* Intializes random number generator */
srand((unsigned) time(NULL));
for (i = 1; i <= 16; i++) {
// 15 because array starts at 0
do {
thenum = rand() % 15;
} while (used[thenum] == 1);
char letter = cubes[thenum][rand() % 5];
used[thenum] = 1;
if (letter == 'q') {
printf("Qu\t");
} else {
printf("%c\t", letter);
}
if (!(i % 4)) {
printf("\n");
}
}
return 0;
}