Page 1 of 1
Unsigned char* concatenation?
Posted: Sun Sep 10, 2006 2:23 am
by cg123
I've been having trouble concatenating unsigned char* values.. does anyone know of a way to do that?
Re:Unsigned char* concatenation?
Posted: Sun Sep 10, 2006 2:58 am
by xenos
What you need is a function like:
Code: Select all
char *strcat( char *strDestination, const char *strSource);
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)
{
char* d = strDestination;
char* s = strSource;
while(*d) d++;
while(*s) *(d++) = *(s++);
*d = 0;
return(strDestination);
}
Re:Unsigned char* concatenation?
Posted: Sun Sep 10, 2006 1:38 pm
by cg123
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?
Posted: Sun Sep 10, 2006 2:22 pm
by Kemp
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?
Posted: Sun Sep 10, 2006 2:24 pm
by cg123
No, I mean I'm not able to clear out the char* 'command' with this:
It retains it's previous value.
Re:Unsigned char* concatenation?
Posted: Sun Sep 10, 2006 2:51 pm
by Kemp
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?
Posted: Sun Sep 10, 2006 9:13 pm
by proxy
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
Re:Unsigned char* concatenation?
Posted: Sun Sep 10, 2006 10:03 pm
by cg123
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.