Hi, I been programming a scrabble solver. For some reason I cant get my functions to take in strings? Ill post my code below but I ran these functions in a diffrent program and they worked fine, but in my current program they dont work at all.
Code:
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void copyword(string &newW,string old);
int searchWord(string word,char letter);
void ShowWord(string word);
struct Words {
char str[30];
};
int main()
{
char str[30];
string word[19000];
int i = 0;
ifstream b_file ( "Final.txt" );
while(!b_file.eof())
{
b_file>> str;
word[i] = str;
i++;
}
b_file.close();
string finallist[12000];
int count = 0;
int letters = 0;
int cpywrd = 0;
string phrase = "EAS";
//REDUCE THE LIST OF WORDS TO ALL WORDS THAT START WITH ONE OF THESE LETTERS
int x = 0;
int sizeX = phrase.length();
for(letters = 0;letters<=phrase.length();letters++)
{
for(count = 0;count<=i;count++)
{
if(word[count][0] == phrase[letters])
{
copyword( finallist[x],word[count]);
x++;
}
}
}
int sWord = 0;
int v1 = 0;
int v2 = 0;
int nextList= 0;
char temp ;
char temp2;
string finallist2[5000];
//SEARCH EACH WORD FOR ALL OF THE LETTERS WHICH RETURNS a 1 IF ITS IN 0 IF ITS NOT.
for(v1 = 0;v1<=x;v1++)
{
for(letters = 0;letters<=phrase.size();letters++)
{
sWord += searchWord(finallist[x].c_str(),phrase[letters]);
}
if(sWord >= finallist[x].length())
cout << "Found Word " ;
ShowWord("HELLO");
cout << endl;
}
cout<< "Reduced to this many words " << x << endl;
cout<< nextList << endl;
system("pause");
return EXIT_SUCCESS;
}
int searchWord(string word,char letter)
{
int i;
int length = word.length();
for(i = 0;i<=length;i++)
{
if(word[i] == letter)
return 1;
}
return 0;
}
void ShowWord(string word)
{
int i;
int length = word.length();
for(i = 0;i<=length;i++)
cout << word[i] ;
}
void copyword(string &newW,string old)
{
int cpywrd;
for(cpywrd = 0;cpywrd<=old.length();cpywrd++)
newW[cpywrd] = old[cpywrd];
}