We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,661 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How do I combine 2 C-Style Strings into an if statement

How do I combine two c-style strings together?

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);
}
}
}
2
Contributors
1
Reply
2 Hours
Discussion Span
7 Months Ago
Last Updated
2
Views
Carc369
Newbie Poster
21 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

See answers to your other thread here

You call strcmp() to compare two character arrays, == doesn't work like it does for std::string class. To solve your problem you will have to first combine the two characters like I showed you in your other thread and then call strcmp() to compare it with another character array. Can't be done all in the same code statement.

Ancient Dragon
Achieved Level 70
Team Colleague
32,275 posts since Aug 2005
Reputation Points: 5,852
Solved Threads: 2,591
Skill Endorsements: 70

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0606 seconds using 2.68MB