Solved

How do I convert a char into unsigned char?

Posted on 2010-09-20
4
587 Views
Last Modified: 2012-05-10
Hi Experts,
I have an array of unsigned char
static unsigned char m_ucTxBuffer[255];
I use memcpy to initialize the first element:
memcpy(&m_ucTxBuffer[0],"\55");
But In another part of the program I want to intialize the second element.  I use Borland C++ and I have an edit box that the user types in the value that will go into the second element.  The way Borland handles EditBoxes is
char normalBuf [10];
strcpy(normalBuf,Edit->Text.c_str())
when I try to copy normalBuf to m_ucTxBuffer[1] it complains that it can't convert char to unsigned char.
How would I put the value in normalBuf into m_ucTxBuffer?
Thanks
0
Comment
Question by:farcuri
[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
4 Comments
 
LVL 12

Accepted Solution

by:
Mohamed Abowarda earned 125 total points
ID: 33720204
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 33720631
Depends what you want the unsigned char buffer to contain.

But if I understand what you want correctly, just do the cast (ie. ignore the compiler warning) :

        char c;
        unsigned char uc = (unsigned char) c;
0
 
LVL 13

Expert Comment

by:Superdave
ID: 33721059
I'm not sure what you're doing makes sense.  memcpy should have three arguments; the third should be 1 if you want to copy one char but you could just as well say
m_ucTxBuffer[0]='\55'; for the first example.
Then, how are you copying the text buffer?  If you want to copy it to positions 1-10 do
memcpy(&m_ucTxBuffer[1],normalBuf,10);

Signed vs. unsigned shouldn't matter much; memcpy should be declared to use void * anyway so I'm surprised if it gives a warning.  If you use strcpy instead, you could just say (char *)&m_ucTxBuffer[1], or (char *)(m_ucTxBuffer+1) which is the same thing.
0
 
LVL 5

Expert Comment

by:greatsubash
ID: 33722821
Hi,
Please refer the following link,
http://www.cplusplus.com/forum/unices/10272/

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

728 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