• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

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].Name;
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!
0
demilune
Asked:
demilune
  • 5
  • 4
1 Solution
 
rajeev_devinCommented:
>> *nm.Zone[ItemNumber8].Name = *ItemName8;
>> cppString = (const char *)nm.Zone[ItemNumber8].Name;

This two statements looks very strange to me.
ItemNumber8 is a char string.
But above you are using it as an index.
Why ?

0
 
demiluneAuthor Commented:
I was told to do that... A friend said it would copy the entire char array and not just once char in the array.
0
 
rajeev_devinCommented:
Can you post the complete code.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
demiluneAuthor Commented:
My code is 1400 lines long... everything that is related to this issue is posted in the question...
0
 
rajeev_devinCommented:
If you are trying to copy the string then do this
strcpy(nm.Zone[index].Name, ItemName8);
0
 
rajeev_devinCommented:
Don't use ItemName8 as index.
0
 
demiluneAuthor Commented:
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
0
 
rajeev_devinCommented:
Simply typecast it
strcpy((char*)nm.Zone[index].Name, (char*)ItemName8);
0
 
demiluneAuthor Commented:
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.'
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now