?
Solved

How do I convert a char into unsigned char?

Posted on 2010-09-20
4
Medium Priority
?
591 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

777 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