Solved

unsigned char getting cutshort

Posted on 2007-03-31
3
232 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 55 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

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall‚Ķ
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

726 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