[ Solved ] Dictionary for Word Based Game...

Hi…
I’m working on a word based game , so there I need to verify a word with the words in english dictionary.For That I have a text file with a list of english words…

Now I have to make a Dictionary object to key and use the words…. how to do that? can anyone tell me with an example…

I tried this…

       CCMutableDictionary < std::string, std::string >  *plistDictionary=new CCMutableDictionary < std::string,std::string > ;


        FILE *fp = fopen(fileName, "r");
        char buf[50] = {0};

        if (!fp)
        {
            CCLOG("can not open file %s", fileName);
            return;// NULL; 
        }
        else
        {
            fgets(buf, 50, fp);

            plistDictionary->setObject(buf,buf);
            CCLOG("read content %s", buf);

            fclose(fp);

        }

But I’m getting error in the line of initializing CCMutableDictionary Object

          CCMutableDictionary < std::string, std::string >  *plistDictionary=new CCMutableDictionary < std::string,std::string > ;

          // error show the line pObject->retain()    ..   /cocos2dx/include/CCMutableDictionary.h:206:9:{206:9-206:19}: error: value of type 'std::basic_string < char > ' is not contextually convertible to 'bool' [3]

can’t I use the string type for the ValueType or KeyType

and in the line of inserting Object into the dictionary

             plistDictionary->setObject(buf,buf);               
             // error show the line pObject->retain()    ..  cocos2dx/include/CCMutableDictionary.h:122:11:{122:4-122:11}: error: member reference type 'std::basic_string < char > ' is not a pointer [3]

someone help…. :frowning:

I think you cannot use CCDictionary in this way.
What’s the content in your char buf[50] after reading the file?

I think you cannot use CCDictionary in this way.

Oh… Do you know a way to implement english dictionary in app?..

What’s the content in your char buf50 after reading the file?
>

That’s the Next Problem…

I couldn’t read the text file…

The file is in the Resources Directory… and I gave only the file name for the path argument… That should work right? or Should I keep the file somewhere else?

Thanks for the reply…

CCDictionary < std::string,CCObject* > **dictionary = new CCDictionary < std::string,CCObject* >;
>
string filePath=new string ) ) ;
FILE
fp = fopen , “r” ) ;
>
if
{
CCLOG (“can not open file %s”, filePath->c_str());
}
else
{
>
while)
{
char buf[4];
fscanf;
if!=0)
{
const char s=buf;
CCString
str=new CCString;
>
>*dictionary - > setObject(str,s);
}
>
}

fclose(fp);
}