6 ms·
There are multiple problems with that code: 1) return(r) He is returning pointer to temporary! When you declare and initialize variables on stack after that fun
by konstmonst 8y ago
There are multiple problems with that code:
1) return(r) He is returning pointer to temporary! When you declare and initialize variables on stack after that function, they will overwrite memory pointed by r.
2) He is assuming size of string pointed by s(including 0) is less than 100 and also the combined sizes of s and t are less than 100. Stack Overflow!
3) Not an errors, but would not pass my code review: Inconsistent Variable declaration, using signed integer for loop where you don't need signed.
Also I would have used strcpy 2 times, or loop 2 times, not two different ways. Beside that, you should not use strcpy, but strncpy to avoid stack overflows.
- saagarjha 8y ago> Inconsistent Variable declaration How so? > I would have used strcpy 2 times You can't do this, because strcpy doesn't give you the length of the string you copied, which is necessary to put the trailing null byte.