char ** initialization and store values
-
Hello Everybody, I am trying to pass some values to char ** (to a third party library). But i am getting some issue in that.
char\*\* ids = new char\*\[m\_Size\]; for(int i=0; i
using that third party function, its creating an output file and in that file the stored value is showing like this.
GROUP : 46,0
GROUP : 44,0
GROUP : 42,0
GROUP : ÝÝÝÝÝÝÝ݆«ãe,0
GROUP : 40,0
GROUP : 38,0But if I give values like this, then in output file, the values are showing fine.
char* ids[6] = {"38", "40", "42", "44", "46", "48"};
in the output file,
GROUP : 38,0
GROUP : 40,0
GROUP : 42,0
GROUP : 44,0
GROUP : 46,0
GROUP : 48,0(see the sequence also)
what i am doing wrong? initialization ? or passing values ?
Thanks,
A. Gopinath. -
Hello Everybody, I am trying to pass some values to char ** (to a third party library). But i am getting some issue in that.
char\*\* ids = new char\*\[m\_Size\]; for(int i=0; i
using that third party function, its creating an output file and in that file the stored value is showing like this.
GROUP : 46,0
GROUP : 44,0
GROUP : 42,0
GROUP : ÝÝÝÝÝÝÝ݆«ãe,0
GROUP : 40,0
GROUP : 38,0But if I give values like this, then in output file, the values are showing fine.
char* ids[6] = {"38", "40", "42", "44", "46", "48"};
in the output file,
GROUP : 38,0
GROUP : 40,0
GROUP : 42,0
GROUP : 44,0
GROUP : 46,0
GROUP : 48,0(see the sequence also)
what i am doing wrong? initialization ? or passing values ?
Thanks,
A. Gopinath.The code looks fine. Because only one of the strings from your array returns wrong data, this element may be corrupted somewhere else. Note also that you must call
ReleaseBuffer()
for each string array element after calling the library function. If not doing so, further accesses may return invalid data. You should also check the documentation of the library if the passed strings are constant or may be changed. If they may be changed, you must pass the max. allowed length toGetBuffer()
. -
Hello Everybody, I am trying to pass some values to char ** (to a third party library). But i am getting some issue in that.
char\*\* ids = new char\*\[m\_Size\]; for(int i=0; i
using that third party function, its creating an output file and in that file the stored value is showing like this.
GROUP : 46,0
GROUP : 44,0
GROUP : 42,0
GROUP : ÝÝÝÝÝÝÝ݆«ãe,0
GROUP : 40,0
GROUP : 38,0But if I give values like this, then in output file, the values are showing fine.
char* ids[6] = {"38", "40", "42", "44", "46", "48"};
in the output file,
GROUP : 38,0
GROUP : 40,0
GROUP : 42,0
GROUP : 44,0
GROUP : 46,0
GROUP : 48,0(see the sequence also)
what i am doing wrong? initialization ? or passing values ?
Thanks,
A. Gopinath. -
Hello Everybody, I am trying to pass some values to char ** (to a third party library). But i am getting some issue in that.
char\*\* ids = new char\*\[m\_Size\]; for(int i=0; i
using that third party function, its creating an output file and in that file the stored value is showing like this.
GROUP : 46,0
GROUP : 44,0
GROUP : 42,0
GROUP : ÝÝÝÝÝÝÝ݆«ãe,0
GROUP : 40,0
GROUP : 38,0But if I give values like this, then in output file, the values are showing fine.
char* ids[6] = {"38", "40", "42", "44", "46", "48"};
in the output file,
GROUP : 38,0
GROUP : 40,0
GROUP : 42,0
GROUP : 44,0
GROUP : 46,0
GROUP : 48,0(see the sequence also)
what i am doing wrong? initialization ? or passing values ?
Thanks,
A. Gopinath.In the first case, the pointers are pointing to memory maintained by the
CStringArray
class. It is likely thatCStringArray
relocated, resized or moved the memory around. So you need to allocate memory for each pointer and copy the contents to the allocated memory. In the second case you have pointers to fixed locations that do not change.«_Superman_» _I love work. It gives me something to do between weekends.
-
In the first case, the pointers are pointing to memory maintained by the
CStringArray
class. It is likely thatCStringArray
relocated, resized or moved the memory around. So you need to allocate memory for each pointer and copy the contents to the allocated memory. In the second case you have pointers to fixed locations that do not change.«_Superman_» _I love work. It gives me something to do between weekends.
I am aurpsised it even runs with out crashing since he is setting his array pointers to the values contained in some string! So if the string was 'this monkley is stupid' the first pointer will have the value of the ASCII codes for 'this', the second pointer ' mon' and so on. Of course these addresses are completely invalid and point to somewhere in his process. If he manipulated them in any way its bye bye process time!
============================== Nothing to say.