0

How do I fix this error?

I get a segmentation error whenever I run this code. I've narrowed down the source of the error but I dont know how to fix it. Please check the comments at the bottom to find the error code. Thank you https://code.sololearn.com/cuRE48uyCl26/?ref=app

16th Sep 2020, 2:22 PM
Nablyn Eku
Nablyn Eku - avatar
2 RĂ©ponses
0
There are 2 main problems. 1. In the second for loop where you reverse the word. You do ++it rather than ++r_it, which cause infinite loop. 2. You didn't empty store1 after reversing the word. It causes the second loop reverse the first and the second word and so on. Also a small problem, you add space when it == input.end() && space != 1. This will make the string add an additional space when the whole string contains only ONE word. Use space > 1 instead.
19th Sep 2020, 3:43 AM
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż - avatar
0
CarrieForle thanks so much.
19th Sep 2020, 10:18 AM
Nablyn Eku
Nablyn Eku - avatar