I'm trying to write a very cheap C++ code snippet to do the following operation on a short null terminated string.
The input is a string like "ABC"
. It is null terminated and has maximum length of 4 (or 5 with the null terminator).
The output goes to a char[4]
which is not null terminated and should be space padded on the right. So in this case it would be {'A','B','C',' '}
It is ok to assume that the input string is properly null terminated, so there's no need to read a second word of the input to make sure. 4 bytes is the longest it can be.
So the code around it looks like this:
char* input = "AB";
char output[4];
// code snippet goes here
// afterward output will be populated with {'A','B',' ',' '}
How cheaply can this be done? If it matters: I'm working with:
Linux 2.6.32-358.11.1.el6.x86_64 #1 SMP x86_64 x86_64 x86_64 GNU/Linux
Lastly, the input is word aligned.