+ 2

Please help

*Can't understand line 44, why he did this *And 41 too why (pos-str) and not (str-pos) https://sololearn.com/compiler-playground/c6RKCv8aK64c/?ref=app

11th Apr 2024, 4:10 PM
Yaniv B
Yaniv B - avatar
3 Antworten
+ 1
Line 41 calculates the index by subtracting `str` from `pos` because `pos` is the starting address of the substring found in `str`. Subtracting `str` from `pos` gives the index or position of `old_w` in the original string `str`. In line 44, the purpose of `strcat(str, temp+index+owlen)` is to concatenate the remaining part of the original string `str` after the occurrence of `old_w` (starting from `index + owlen`) to the modified `str` after replacing `old_w` with `new_w`. Here, - `temp` is a buffer where a copy of the string `str` is stored for manipulation. - `index` represents the index or position in the original string where `old_w` was found. - `owlen` is the length of the string `old_w`. - `temp+index+owlen` points to the location in `temp` immediately after `old_w` ends.
11th Apr 2024, 4:39 PM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
12th Apr 2024, 9:03 AM
Xavier Borgoyary Basumatary
Xavier Borgoyary Basumatary - avatar
+ 1
Cpp
12th Apr 2024, 9:03 AM
Xavier Borgoyary Basumatary
Xavier Borgoyary Basumatary - avatar