I'm trying to write some code which will take the value from one variable ( multiple guesses ), format it and split it up into diffrent variables (one for each guess). I have a set of if statements which check the length of the variable (to see how many guesses have been entered) and assign a variable a number (the number of guesses). These if statements are below:
Code:
if ( strlen( guess ) >= 4 )
{
guess_number = 1;
}
if ( strlen ( guess ) >= 8)
{
guess_number = 2;
}
if ( strlen ( guess ) >= 12)
{
guess_number = 3;
}
if ( strlen ( guess ) >= 16)
{
guess_number = 4;
}
I've made this loop:
Code:
if (guess_number >=1){
n = 1;
for(i = 0; i < 4; i++){
if ((guess[n] == 'r')||(guess[n] == 'R')){
formattedguess1[i] = COLOR_RED;
}else if ((guess[n] == 'b')||(guess[n] == 'B')){
formattedguess1[i] = COLOR_BLUE;
}else if ((guess[n] == 'y')||(guess[n] == 'Y')){
formattedguess1[i] = COLOR_YELLOW;
}else if ((guess[n] == 'g')||(guess[n] == 'G')){
formattedguess1[i] = COLOR_GREEN;
}else if ((guess[n] == 'w')||(guess[n] == 'W')){
formattedguess1[i] = COLOR_WHITE;
}else if ((guess[n] == 'o')||(guess[n] == 'O')){
formattedguess1[i] = COLOR_ORANGE;
}else {
valid = 1;
printf("The guess you entered isn't valid, please enter it in the format of r = red and o = orange");
break;
}
n++;
}
}
Which moves the first 4 characters in the variable guess to formattedguess1 after being formatted. "i" being the character number in the formattedguess and "n" the number its on from the guess variable. I'm planning on having a identicle loop after which if the number of guesses is greater than 2 it does the same thing but for the 5,6,7,8 value of guess since n gets incremented each time around.
The problem which i'm having is that it always display's the message in the else statement.
I have apsolutly no idea why this is happening and am hoping someone will have an explination??
Thanks