-
string help
Hi im making a ai program for scrabble and cant get my string to = another string
here is my code and I marked it with a **HERE**
Code:
#include <fstream>
#include <iostream>
#include <cstring>
using namespace std;
struct Words {
char str[30];
};
int main()
{
char str[30];
string word[32000];
int i = 0;
ifstream b_file ( "Final.txt" );
while(!b_file.eof())
{
b_file>> str;
word[i] = str;
i++;
}
b_file.close();
string finallist[32000];
int count = 0;
int letters = 0;
string phrase = "EDW";
int x = 0;
for(letters = 0;letters<=phrase.length();letters++)
{
for(count = 0;count<=i;count++)
{
if(word[count][0] == phrase[letters])
{
strcpy(finallist[x],word[count]); //**HERE**
x++;
}
}
}
cout<< "Reduced to this many words " << x << endl;
system("pause");
return EXIT_SUCCESS;
}
-
You need to use C++ strings.
You should use this:
#include <string>
....
I can't even compile your code.
Function strcpy has this prototype:
Code:
char *strcpy(
char *strDestination,
const char *strSource
);
Pay attention char * and not string...
- Micko
-
string mystring = "a bunch of words yet i dont need [ ] c++ strings are awsome";
-
>Hi im making a ai program for scrabble and cant get my string to = another string
Instead of:
Code:
strcpy(finallist[x],word[count]); //**HERE**
Use:
Code:
finallist[x] = word[count];