-
Since you're implementing your own strcat function, I would do it this way:
Code:
bool strcat(char* dst, const char* src, uint32_t dest_length)
{
const char* tmp = src;
uint32_t count_src = strlen(src);
uint32_t count_dst = strlen(dst);
if (count_src + count_dst + 1 > dest_length)
return false;
dst += count_dst;
while (*src) *dst++ = *src++;
*dst = 0;
return true;
}
-
Thanks... Will be used probably in 3-4 months... and I mean many thanks.
As for my understanding of this function, it does way more than my currnent needs and I need to "downsize" purposes. I know I make it sound pretty vague. This is a mini project for current fixes.
The most important part is using the "array" way of char, meaning indexes, rather than pointers (that was our supervisor's request). In 5-6 months time, all of the bigger project will become dynamic and in a c++ kind of way (while decremanting the c syntax entirely).
And again, many thanks for your implementationg of strcat()...
-
Well, no, it doesn't do much.
It copies just like strcat, but it also checks that the buffer (destination) you passed is big enough to hold the data. If it isn't, it returns false, and if it it succeeds, it returns true.
But it also uses pointers instead of indexes, but that's not difficult to change.
You're still welcome to try to understand it. A debugger might help.
-
I don't see any problem there. It has to do with something how you are using the function.
-
That's exactly what I meant...
I will use it in the bigger project, but not yet (since the current request is using a "void" syntax
and 2 pointers as parameters).
I'm guessing that our supervisor already implemented his own project, and probably used the functions just as he requested.
-
I understand that you shouldn't use it, but you can still dissect it and learn something from it.
But... as you go deeper into C++ (if I get you correctly), you won't need strcat at all.
-
And as I already said, I took it and am "learning something from it"...
Nice to know that there are good people out there after all... for:
"There's the respect that's makes calamity of so long lives,
for who would bear the weeps and scorns of time?", or so they say...