+ 2
how to remove useless output after reverse of string in code?
7 Respuestas
+ 3
You have:
for(i=l;l>=0;i--)
That should be:
for(i=l;i>=0;i--)
Your original code's for loop basically never stops, so it ends up reading garbage in memory, since i keeps decrementing indefinitely. All the junky characters you see is your program interpreting as characters the contents of the memory following the array b.
+ 3
thnks
+ 2
btw any suggestion how to remove silly mistkaes like this?
any suggestions for reading code?
+ 1
I correct myself for the last part: the junky memory is the one preceding b, since i becomes a negative number
+ 1
Well, you need to get used to read code, and that comes with experience. Such mistakes can be hard to find. A big warning sign in this case was the junky characters: that is usually a sign of reading garbage and interpreting it as a string, something that happens when you forget the null terminator.
There are some tools that can help though: on Linux there is Valgrind, that detects this kind of mistakes (and much more).
+ 1
oh thnks a lot for this info
+ 1
You're very welcome! :)