[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Help... Output is a single char not a string...

Posted on 2006-06-29
9
Medium Priority
?
193 Views
Last Modified: 2010-04-24
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
Comment
Question by:demilune
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 17015192
>> *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
 

Author Comment

by:demilune
ID: 17015251
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
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 17015326
Can you post the complete code.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:demilune
ID: 17015348
My code is 1400 lines long... everything that is related to this issue is posted in the question...
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 17015359
If you are trying to copy the string then do this
strcpy(nm.Zone[index].Name, ItemName8);
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 17015361
Don't use ItemName8 as index.
0
 

Author Comment

by:demilune
ID: 17015370
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
 
LVL 12

Accepted Solution

by:
rajeev_devin earned 1000 total points
ID: 17015377
Simply typecast it
strcpy((char*)nm.Zone[index].Name, (char*)ItemName8);
0
 

Author Comment

by:demilune
ID: 17015470
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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question