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
Solved

unsigned char getting cutshort

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
SendMessage fails while PostMessage works 2 122
C++ Class Serialization, Encapsulation and Formatted Output 8 76
C++ question 3 70
C++ Code Issue 4 22
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

766 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