I'm not even sure what the hell is going on there. I looked at it and though, WTF is that! (no offense)
Maybe someone who is a pointer expert can fully explain what is going on there but to remedy that code I would try something like this: |
No idea what's going on there? It's literally the same thing as what you posted except it uses pointer arithmetic instead of the subscript operator.
And what you posted doesn't remedy it. Line 11 screws over everything, and the logic is flawed (as it is in my OP) because it should be a break statement on line 8, a return 0 on line 13 and check if s2[i+1] == '\0' somewhere in the for loop, returning s2 if that is true.
How is what either of us posted what C should look like, but not C++? Yes, pointers are more commonly used in C, but what does that have to do with it? This program is valid in either language.
Hopefully this clears up your "WTF IS THAT??!?!?!!!111one"
Thank you, vin, for pointing out the problem in my program, and I've gotten it to work since then.