I've created a Word scribble solver and it basically computes the permutations of a given word and compares it with the available dictionary. But the problem is I've to copy a char pointer into an array char variable to compare them and I don't know how to do it. Below is my code snippet:
#include<fstream>
#include<string>
#include<ctype>
using namespace std;
void swap(char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}
void permute(char *a, int l, int r)
{
char word[25], word1[25];
fstream flame;
if(l == r)
{
word1 = *a; /* <— Error! */
flame.open("dic.sly", ios::in);
while(!flame.eof())
{
flame << word;
tolower(word[0]);
if(strcmp(word, word1) == 0)
cout << word;
}
flame.close();
}
else
{
for(int i = l; i <= r; i++)
{
swap((a + l), (a + i));
permute(a, l + 1, r);
swap((a + l), (a + i));
}
}
}
void main()
{
char str[] = "lonea";
int n = strlen(str);
permute(str, 0, n - 1);
}
I've quoted where I'm getting the error. Please, correct if there are any mistakes.