Solved

unsigned char getting cutshort

Posted on 2007-03-31
3
205 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-
  • 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now