Why does this code outputs '@'? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why does this code outputs '@'?

I try to remove any space or command character from a c-string, I increment the pointer so the array will start from index 1, but it prints @... https://code.sololearn.com/cyC4XdCoQyGZ/?ref=app

25th Jul 2017, 12:30 AM
Andrés04_ve
Andrés04_ve - avatar
8 Answers
+ 3
I have changed your if statement to be like: if(*s <= ' ' && *s != '\0') it should work better now, test it and tell if it works :D
25th Jul 2017, 1:29 AM
Jakub Stasiak
Jakub Stasiak - avatar
+ 2
Strange problem. I will try to figure it out in the morning (3am here), what can I advise you right now is to make yourself familiar with erase-remove idiom in C++. It can delete spaces easier and faster :D (recursion is really slow)
25th Jul 2017, 1:19 AM
Jakub Stasiak
Jakub Stasiak - avatar
+ 2
Thanks sir! It's very strange, I called the function twice (with same arguments) and it printed 'PP' ...
25th Jul 2017, 1:24 AM
Andrés04_ve
Andrés04_ve - avatar
+ 1
Thanks, it works :D !
25th Jul 2017, 1:42 AM
Andrés04_ve
Andrés04_ve - avatar
+ 1
I forgot evaluate if I get the end of string :p
25th Jul 2017, 1:42 AM
Andrés04_ve
Andrés04_ve - avatar
+ 1
Now I see the function doesn't modify the array as itself, only a copy... How can I pass an array/pointer by reference?
25th Jul 2017, 4:26 PM
Andrés04_ve
Andrés04_ve - avatar
+ 1
Well, I just wrote s=eval(s) :p Finally my language can print any string with < :D < 'Hello World'
25th Jul 2017, 4:45 PM
Andrés04_ve
Andrés04_ve - avatar
25th Jul 2017, 5:09 PM
Andrés04_ve
Andrés04_ve - avatar