Timeline for XOR two strings
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 21, 2020 at 20:27 | history | edited | LambdaBeta | CC BY-SA 4.0 |
-1 from ceilingcat
|
| Jul 20, 2020 at 23:07 | history | edited | LambdaBeta | CC BY-SA 4.0 |
some safer variants added.
|
| Jul 20, 2020 at 22:47 | comment | added | LambdaBeta | Let us continue this discussion in chat. | |
| Jul 20, 2020 at 22:47 | comment | added | LambdaBeta | Wow, my bad :P wrote that out too quickly. Try it online! That one fixes the wrong name issue. | |
| Jul 20, 2020 at 22:36 | comment | added | Noodle9 | You're still reading past the end of a string. Don't do that. It's making my eyes bleed! T_T | |
| Jul 20, 2020 at 22:32 | comment | added | LambdaBeta |
same can be done in mine. it also still requires work outside of the function in terms of free. A solution would be something like this: Try it online!
|
|
| Jul 20, 2020 at 21:38 | comment | added | Noodle9 |
There are many ways to make your code cleaner. Not reading past the end of strings for starters. The point is that work is being done outside of your function to make it work. To change mine to return a string is trivial and certainly doesn't involve passing string lengths. Simply malloc a string buffer based on the maximum strlens of the inputs and return that pointer after creating the result there.
|
|
| Jul 20, 2020 at 20:27 | comment | added | LambdaBeta | I agree it isn't the fairest, but given how strings are represented in C there isn't a much cleaner way to write this as a function. Your solution doesn't provide any means by which to access the new string, other than trapping the output stream. The only truly portable way would be to take 6 parameters: a, len(a), b, len(b), buffer, len(buffer). But defensive coding has never really been the goal of these submissions ;) | |
| Jul 20, 2020 at 1:23 | comment | added | Noodle9 | You're also relying on memory past the end of the shorter string to be initialised to zero. | |
| Jul 20, 2020 at 1:15 | comment | added | Noodle9 | You're relying on the first string storing as much memory as the second string in case the second string is longer than the first. That's not really playing fair. Certainly not how strings work in C. | |
| Jul 19, 2020 at 23:09 | history | answered | LambdaBeta | CC BY-SA 4.0 |