Unsigned char* concatenation?
Unsigned char* concatenation?
I've been having trouble concatenating unsigned char* values.. does anyone know of a way to do that?
Re:Unsigned char* concatenation?
What you need is a function like:
It normally searches the end of strDestination and copies the contents of strSource at that place. It should look similar to this one:
Code: Select all
char *strcat( char *strDestination, const char *strSource);
Code: Select all
char *strcat( char *strDestination, const char *strSource)
{
char* d = strDestination;
char* s = strSource;
while(*d) d++;
while(*s) *(d++) = *(s++);
*d = 0;
return(strDestination);
}
Re:Unsigned char* concatenation?
Thanks, that works perfectly.. but now I'm having trouble clearing the value. Instead of being cleared before a new value is inserted, it just stacks up and eventually crashes the kernel.
Re:Unsigned char* concatenation?
If you mean that the characters being added on the end overwrite things then that's because the destination must have enough space allocated already to handle both strings. You could try adding them both to a third (larger) buffer if that's not possible to arrange.
Re:Unsigned char* concatenation?
No, I mean I'm not able to clear out the char* 'command' with this:
It retains it's previous value.
Code: Select all
command = ""
Re:Unsigned char* concatenation?
You have to remember that a char* is not a string, the best case result for setting it equal to "" is that the first character will be made a null, thus pretending it is an empty string, the rest of it will still be there though.
Re:Unsigned char* concatenation?
cg123, no offence, but if you don't know how strings work in c (in that you are dealing with pointers to null terminated sequences of characters) and how to properly manipulate them, you have no business writing an OS.
This isn't meant to be hostile or insulting, just trying to suggest you do some more work with projects in user land until you REALLY know c/c++ well before diving into the kernel.
proxy
This isn't meant to be hostile or insulting, just trying to suggest you do some more work with projects in user land until you REALLY know c/c++ well before diving into the kernel.
proxy
Re:Unsigned char* concatenation?
The main reason I've been having trouble with variables is that I'm working on 3 different projects at once right now - one in PHP, one in Lua, and one in C++. I'm consistently getting the way variables work in them mixed up. I can see why you would say that, though.