demilune
asked on
Help... Output is a single char not a string...
Here is what I have...
unsigned char ItemName8[16];
struct Names
{
struct
{
unsigned char Name[16];
} Zone[176];
...
*nm.Zone[ItemNumber8].Name = *ItemName8;
cppString = (const char *)nm.Zone[ItemNumber8].Nam e;
Memo1->AppendText(" Item Name: " + gcnew System::String(cppString.c _str()) + "\r\n");
My question is: when I output the ItemName8 directly, it will output the entire array. When I store the value of ItemNumber8 to the nm.Zone[].Name struct and output that, it just outputs the first char.
Any thoughts? Code is helpful...
Thanks!
unsigned char ItemName8[16];
struct Names
{
struct
{
unsigned char Name[16];
} Zone[176];
...
*nm.Zone[ItemNumber8].Name
cppString = (const char *)nm.Zone[ItemNumber8].Nam
Memo1->AppendText(" Item Name: " + gcnew System::String(cppString.c
My question is: when I output the ItemName8 directly, it will output the entire array. When I store the value of ItemNumber8 to the nm.Zone[].Name struct and output that, it just outputs the first char.
Any thoughts? Code is helpful...
Thanks!
ASKER
I was told to do that... A friend said it would copy the entire char array and not just once char in the array.
Can you post the complete code.
ASKER
My code is 1400 lines long... everything that is related to this issue is posted in the question...
If you are trying to copy the string then do this
strcpy(nm.Zone[index].Name , ItemName8);
strcpy(nm.Zone[index].Name
Don't use ItemName8 as index.
ASKER
When I do that, I get the compiler error:
error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned char [16]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned char [16]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It works :)
If you don't mind, is there any other way to do it. The strcpy function was depreciated and I would like to stay with current "mothods" if possible...
warning C4996: 'strcpy' was declared deprecated
C:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(73) : see declaration of 'strcpy'
Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
If you don't mind, is there any other way to do it. The strcpy function was depreciated and I would like to stay with current "mothods" if possible...
warning C4996: 'strcpy' was declared deprecated
C:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(73) : see declaration of 'strcpy'
Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
>> cppString = (const char *)nm.Zone[ItemNumber8].Nam
This two statements looks very strange to me.
ItemNumber8 is a char string.
But above you are using it as an index.
Why ?