You didn't write a terminating zero, you just filled the array with spaces and 'R's all the way to the end.
Just add my[l - 1] = 0 somewhere after the for.
thanks for the reply. i had tried and its work, but what is the function of terminating zero? does it affect if the size of the array change to smaller or larger size?
An "old" C-Style Array always terminates with '/0' that tells to the compiler that the allocated space in memory pointing to them is terminated. It is the raw version of vector<int> v{1,2,3}; v.size(); . In C++ is preferable to use vectors because are more "smart" than arrays, they know "their size" and are standardized. Hope this helps :)