So , unfortunately I encountered another problem with a program I'm trying to create. First of all I'm totally new to C Programming and I'm trying to create a Word Search .
I have this piece of code which is in C++ and I'm trying to turn it into C :
#include <iostream>
using namespace std;
int main()
{
char puzzle[5][5] = {
'A', 'J', 'I', 'P', 'N',
'Z', 'F', 'Q', 'S', 'N',
'O', 'W', 'N', 'C', 'E',
'G', 'L', 'S', 'X', 'W',
'N', 'G', 'F', 'H', 'V',
};
char word[5] = "SNOW"; // The word we're searching for
int i;
int len; // The length of the word
bool found; // Flag set to true if the word was found
int startCol, startRow;
int endCol, endRow;
int row, col;
found = false;
i = 0;
len = 4;
// Loop through each character in the puzzle
for(row = 0; row < 5; row ++) {
for(col = 0; col < 5; col ++) {
// Does the character match the ith character of the word
// we're looking for?
if(puzzle[row][col] == word[i]) {
if(i == 0) { // Is it the first character of the word?
startCol = col;
startRow = row;
} else if(i == len - 1) { // Is it the last character of the
// word?
endCol = col;
endRow = row;
found = true;
}
i ++;
} else
i = 0;
}
if(found) {
// We found the word
break;
}
}
if(found) {
cout << "The word " << word << " starts at (" << startCol << ", "
<< startRow << ") and ends at (" << endCol << ", " << endRow
<< ")" << endl;
}
return 0;
}
However , I've encountered a problem as I just noticed that C Programming doesn't support Booleans.
I'm using it so the user enters the word he is searching for ( for example: boy) , the user also enters the length ( 3 ) and then the user will enter the co-ordinates of the first and last letters of the word. When the user enters the following I'm planning to get the co-ordinates from the code above and than compare them with what the user entered. If they doesn't match the user guessed incorrectly , and if they match the user guessed it correctly.
I've also tried the stdbool.h
library , however it didn't work because the library wasn't found.
Is there any other way instead of stdbool.h
? I know you use true = 1 , false = 0 however I don't know exactly how to interpret it in the following code.
Thanks in advance.