Initialization file issue
  • bluecodebluecode August 2011
    Hi guys

    I'm loading a bunch of string from an .ini which goes well until the last value is read. On this all previous values are set to the last string loaded.

    eg

    ini file
    1
    2
    3
    4
    [strings]
    SOME_STRING_1=green
    SOME_STRING_2=blue
    SOME_STRING_3=red

    cpp code
    1
    2
    3
    SOME_STRING_1 = hge->Ini_GetString("strings","SOME_STRING_1","Apple");
    SOME_STRING_2 = hge->Ini_GetString("strings","SOME_STRING_2","Orange");
    SOME_STRING_3 = hge->Ini_GetString("strings","SOME_STRING_3","Pear");


    If you dump the value of SOME_STRING_1 to a log mid load it will read the value in the ini "green", but after all loads are complete the value of SOME_STRING_1 is now red.

    Anyone have any idea what's going on?
  • ProfEclipseProfEclipse August 2011
    Ini_GetString returns a pointer to a statically allocated buffer. You need to copy the string to your own buffer.
  • kvakvskvakvs August 2011

    Ini_GetString returns a pointer to a statically allocated buffer. You need to copy the string to your own buffer.


    that,
    or start using c++ and c++ strings, and stop using C strings. C++ strings do copying automatically.
  • bluecodebluecode August 2011
    Thanks guys.

    I've solved it, using strcpy_s() to move the string.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion

Who's Online (2)