0

Basically I'm trying to see if the first letter is in the dictionary... then if it is.. check if the first and second letter are in the dictionary.. and if it is... check if the first, second, and third letter are in the dictionary... and so on and so forth.

I'm just displaying the code I'm having trouble with. The rest of the code works I'm just having trouble with the line 8 if statement. I know I'm using strncat wrong (never used it before). Idk if I'm correctly using it.

Edit: I cannot use strings. Only C-Style Strings.

void checkSecondLetter(char boggleBoard[6][6], char firstLetter){
    char secondLetter[3]; 
    for(int checkRow = 0; checkRow  < 6; checkRow++)
        for(int checkColumn = 0; checkColumn < 6; checkColumn++)
            for(int checkDictionary = 0; checkDictionary < MaxNumberOfWords; checkDictionary++){
                secondLetter[0] = firstLetter;
                secondLetter[1] = boggleBoard[checkRow][checkColumn];
                if (strncat(secondLetter[0], secondLetter[1]) == *theWords[checkDictionary])
                    cout << "The word is " << secondLetter[0] << secondLetter[1] << endl;
                }
}


void checkFirstLetter(char boggleBoard[6][6]){
    char firstLetter;
    for(int checkRow = 0; checkRow  < 6; checkRow++)
        for(int checkColumn = 0; checkColumn < 6; checkColumn++)
            for(int checkDictionary = 0; checkDictionary < MaxNumberOfWords; checkDictionary++){
                if (boggleBoard[checkRow][checkColumn] == *theWords[checkDictionary]){
                    firstLetter = boggleBoard[checkRow][checkColumn];
                    boggleBoard[checkRow][checkColumn] = '*';
                    checkSecondLetter(boggleBoard,firstLetter);
                }
            }
}

Edited by pritaeas: Moved.

2
Contributors
1
Reply
3
Views
4 Years
Discussion Span
Last Post by Banfa
0

A C string is and array of char. It is zero terminated, that is the last char in the string (but not necessarily the array) is the ASCII nul or '\0' or plain 0 (different names for the same thing).

All characters up to the zero terminator must be printable characters.

You have an array of char char secondLetter[3]; at line 6 and 7 you set the first 2 characters of that string, to make if a C string all you have to do is set secondLetter[2] tp '\0', secondLetter[2] = '\0';.

strcat is for concatinating 2 C strings but you have passed it 2 char, anyway there is no need for it you already have your string in secondLetter. You can not compare C strings with == you will compare the pointers and they are unlikely to be the same. To compare C strings you need to call strcmp or strncmp from the header 'cstring'

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.