Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4
Try to revisit your code there most be a mistake that is causing it not to run properly.
7th May 2020, 3:33 PM
Ambassador Viva 🇸🇱
Ambassador Viva 🇸🇱 - avatar
+ 3
But you know that the index starts at 0 and the last index is length() - 1? ;)
5th May 2020, 11:08 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Szymon I found this about npos: http://www.cplusplus.com/reference/string/string/npos/ I am wondering if you really know what npos is. I don't understand it and would be interested in how you get the idea to use npos.
5th May 2020, 1:08 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Okay, now I got it. In the reference about string.find() it is mentioned that it returns npos if no matches were found. Thanks.
5th May 2020, 1:29 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
I think your second loop is wrong. i = 0 -> p.length() - 0 = p.length() p[p.length()] out of bounds -> should be garbage value. In java you would get an exception.
5th May 2020, 10:52 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Szymon I have my doubts about this: p[i] = (char) 0. The char is not visible. But did you check p.length() after the first loop? Not visible is not the same as not there. I would say there is still a char. How does your java code looks like? Can't you convert your java code to c++?
5th May 2020, 11:36 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Your code is not working. It does not remove all non letters. I don't think that npos is helpful here. Btw: Why don't you just print p in reversed order with the condition that p[i] is inside alpha? pseudo code: for i = length - 1; i >= 0; i-- : if p[i] in alpha : print p[i] else continue
5th May 2020, 12:34 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Nothing's wrong with this system... just change the last code to "cout << d.length()" to find the mistake I'll give you a hint: Your code has made a mess of whitespace (I don't know c++.. it's just my idea)
7th May 2020, 5:21 AM
Bot
Bot - avatar
0
Szymon Can you please show me your new code?
5th May 2020, 12:24 PM
Denise Roßberg
Denise Roßberg - avatar
0
Szymon And erase? Maybe you did something there. But you deleted your code. So I can't test it.
5th May 2020, 1:32 PM
Denise Roßberg
Denise Roßberg - avatar
- 2
any one can help me?
5th May 2020, 5:58 PM
Beed
- 3
Samsung 8
7th May 2020, 4:58 AM
Anand Kumar
Anand Kumar - avatar