+ 1

I tried to create a function similar to strcat in c and name it fstrcat.

I noticed strcat() does't prevent buffer overflow so I created fstrcat() which tries to prevents buffer overflow. Here is the link to the code : https://code.sololearn.com/cwQztB1av5pt But it doesn't seem to work there is no output. I am not able to understand where I made the mistake. Any help would be great.

12th May 2019, 9:31 AM
Zeeking99
Zeeking99 - avatar
3 Respostas
+ 6
combinedstr needs to be casted to a pointer to char instead of a char. Also, personally I'd recommend to use malloc((combinedlen+1)*sizeof(char)) instead of malloc(combinedlen+1*sizeof(char)). It doesn't make a difference here because 1 char = 1 byte but for every other data type the notation without parentheses would lead to wrong results
12th May 2019, 9:47 AM
Anna
Anna - avatar
+ 4
you're creating a replacement for a built in function and you're still using the function in your code. why don't you iterate over it, like joining 2 arrays together
12th May 2019, 11:29 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 2
Thanks Anna it worked. But I am getting some weird characters before the combined string in the Solo Learn compiler but not in other online compilers I've tried.
12th May 2019, 9:55 AM
Zeeking99
Zeeking99 - avatar