?
Solved

unsigned char getting cutshort

Posted on 2007-03-31
3
Medium Priority
?
242 Views
Last Modified: 2010-04-01
Hello,

I have a small problem,

I have a array of unsigned char, for example lets say this,
0x11 0x22 0x33 0xFF 0x44

I then +1 to each of these using a for loop,
array[i] = array[i]+1;

So it looks like this,
0x12 0x23 0x34 0x00 0x45

But now it gets cut short because of the null char 0x00,
Is there anyway to overcome this problem?
0
Comment
Question by:-Karamja-
[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
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 220 total points
ID: 18829512
>> But now it gets cut short

That only depends on how you output the array.

Try this for example :

    unsigned char arr[5] = { 0x11, 0x22, 0x33, 0xFF, 0x44 };
    int i = 0;
    for (i = 0; i < 5; ++i) {
      ++(arr[i]);
    }
    for (i = 0; i < 5; ++i) {
      cout << hex << arr[i] << " ";
    }
    cout << endl;
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 18829515
Can you show your code - and the location where you notice the problem ?
0
 
LVL 2

Author Comment

by:-Karamja-
ID: 18829588
Ok, I was being stupid :(
Your code triggered something in my head though so I guess the points are yours ;)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

771 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