This code worked in this compiler of SoloLearn but why isn't it working on other compiler? Please Help me. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

This code worked in this compiler of SoloLearn but why isn't it working on other compiler? Please Help me.

https://code.sololearn.com/c4b16lgxw8zS/?ref=app Turbo C++ is unable to trace the first while loop of the function definition and also skipping the char declaration in each function. And console entered the 2nd loop around 34 times. And gave the message ABNORMAL PROGRAM TERMINATION after 2-3 special characters. In NotePad++ I'm getting "UP╠ a" after giving the input TIPU.

23rd Apr 2020, 8:33 AM
Tipu Sultan
Tipu Sultan - avatar
6 Answers
+ 4
Turbo C++ is discontinued and hasn't had an updated stable build release since 2006. Use a more modern compiler like gcc.
23rd Apr 2020, 9:05 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
The largest problem is in the while loop on line 18. It decrements pointer 'a' past the beginning of the string. Decrementing stops only when there happens to be a null byte in memory before the string. As the loop continues, it can cause l_ptr to increment past the end of the output buffer, s2. Then it will overwrite other variables on the stack and change r_ptr and l_ptr. Behavior gets unpredictable at that point. (I tested this scenario and determined empirically that it happens).
23rd Apr 2020, 7:18 PM
Brian
Brian - avatar
0
But why the compiler of this app giving the correct output? And isn't it possible to write the code without malloc() or other memory allocation functions?
23rd Apr 2020, 9:38 AM
Tipu Sultan
Tipu Sultan - avatar
0
There was problem to Concatenate two strings using function which must return pointer/string to the calling function. I didn't use malloc but it did work.
23rd Apr 2020, 1:42 PM
Tipu Sultan
Tipu Sultan - avatar
0
Would you please recommend me some books for C language?
23rd Apr 2020, 5:16 PM
Tipu Sultan
Tipu Sultan - avatar
0
Turbo C++ is discountinued and dilapidated for who knows how long. You should use a more modern and updated compiler such as Clang, GCC or MSVC++
24th Apr 2020, 1:29 PM
s.f