Hi there,
I have to make a function valid_dice_selection that helps another function select_dice to check the length of a string and besides that it has to check that the characters in that string only include 'x', 'X' and '-'.
Ive gotten so far:
Im not sure how to check wether input(which is the string i have to work with i suppose) only contains 'x', 'X' or '-'.
I was thinking with some sort of for loop (hence the input) and checking the value of each array element one by one?
static int is_valid_dice_selection (char input [])
{
char input[i];
int length;
length = strlen(input);
for (i = 0; i < strlen(input)-1; i++)
{
}
return 0;
}
static void select_dice (int reroll_flags [])
{
int i;
char reroll_input [NUM_OF_DICE + 1];
do
{
printf ("Mark the dices you want to reroll with a X, the others with a -.\n");
printf ("For example, if you want to reroll the dices 2 and 5, you'll enter: \"-X--X\"\n");
scanf ("%5s", reroll_input);
}
while (! is_valid_dice_selection (reroll_input));
for (i = 0; i < NUM_OF_DICE; i++)
{
if (tolower (reroll_input [i]) == 'x')
reroll_flags [i] = 1;
else if (reroll_input [i] == '-')
reroll_flags [i] = 0;
}
}