I have an anagram program that if you type in a word's characters in any order, the dictionary file will be able to export it. However, my assignment is to build words that are shorter than the inputted search area in a one-to-one letter correspondance. An example of this would be inputting "abel's" and returning "abe, abe's, abel, abel's, able, ables", or whatever the words could fit the criteria.
I've had suggestion from my classmate that I should convert the string to a char, but I'm unsure if this is what I should perform (my test of this is commented out).
#include"WordClass.h"
#include<iostream>
#include<conio.h>
#include<vector>
#include<string>
#include<fstream>
#include<algorithm>
using namespace std;
int main()
{
WordClass hold;
bool output=false;
ifstream inFile;
string input, search, store, newin, newsea;
//char chrArray[50], chrArray2[50];
cout<<"Enter your search letters: ";
getline(cin,input);
newin=hold.sortletters(input);
hold.lowercase(newin);
hold.removenonletter(newin);
/*for(int n=0; n<(int)input.length(); n++)
{
if(input[n]=='1')
{
chrArray[n]=input[n];
}
}*/
cout<<endl;
inFile.open("WordClassdictionaryfile.txt");
while(!inFile.eof())
{
output=false;
inFile>>search;
store=search;
newsea=hold.sortletters(search);
hold.lowercase(newsea);
hold.removenonletter(newsea);
/*for(int n=0; n<(int)search.length(); n++)
{
if(search[n]=='1')
{
chrArray2[n]=search[n];
}
}*/
if(hold.anagram(newin, newsea))
{
cout<<store<<endl;
}
else
{
continue;
}
}
cout<<endl<<"Finished"<<endl;
return 0;
getch();
}
Anagram function in WordClass
bool WordClass::anagram(string newin, string newsea)
{
count=0;
vector<string>word1;
vector<string>word2;
word1.push_back(newin);
word2.push_back(newsea);
if(newin.size()!=newsea.size())
{
return 0;
}
length=word1.size();
for(int i=0; i<length; i++)
{
for(int j=0; j<length; j++)
{
if(word1[i]==word2[j])
{
count++;
}
}
}
if(count==length)
{
return true;
}
else
{
return false;
}
}