Note that there are some explanatory texts on larger screens.

plurals
  1. POError comparing strings in Cocos2d-x
    primarykey
    data
    text
    <p>I am using cocos2d-x to create an Android game.</p> <p>I am calling a static function within a different class that checks if a given username and password is correct. The function returns a string, "yes" if both username and password are correct, "no" otherwise.</p> <p>I then compare the string to decide what to do next. The problem I am having is that in CCLOG it prints response is "yes", however the if branch does not execute, i.e. strcmp(result.c_str(), "yes") does not return true but CCLOG prints result to be "yes".</p> <p>Here is my code :</p> <pre><code>// LogInPage if (((CCMenuItemSprite*) pSender)-&gt;getTag() == 0) { string username = string(m_pEditUsername-&gt;getText()); string password = string(m_pEditPassword-&gt;getText()); string result = SQLDatabase::logIn(username, password); CCLOG("RESULT IS %s", result.c_str()); if (strcmp(result.c_str(), "yes") == 0) { CCLOG("IN IF BRANCH"); CCDirector::sharedDirector()-&gt;replaceScene(PlayMultiplayerPage::scene()); } } </code></pre> <p>// STATIC LOGIN FUNCTION</p> <pre><code>string SQLDatabase::logIn(string username, string password) { stringstream strm; strm &lt;&lt; "http://****.net/select_functions.php? function=logIn&amp;username=" &lt;&lt; username &lt;&lt; "&amp;password=" &lt;&lt; password; CURL* curl; CURLcode res; string result; curl = curl_easy_init(); string URL = strm.str(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, URL.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Write_To_String); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;result); res = curl_easy_perform(curl); curl_easy_cleanup(curl); CCLOG("curl return code is %i", (int) res); CCLOG("response is \n %s", result.c_str()); } return result; } </code></pre> <p>// WRITE_TO_STRING FUNCTION</p> <pre><code>size_t SQLDatabase::Write_To_String(void *ptr, size_t size, size_t count, void *stream) { ((string*) stream)-&gt;append((char*) ptr, 0, size * count); return size * count; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload