*s = "";
if (('0' <= *s && *s <= '9') || *s == ' ') {
s is a char * variable. So *s should point to a char. "" is not a char. It's a zero length string. A string is an array of characters. So this is effectively a pointer. Which is, effectively, an int. Hence on this line
Code:*s = "";
you get a warning as the type on the right is a pointer and the expected type is a character.
One problem is in this line:
Code:if (('0' <= *s && *s <= '9') || *s == ' ') {
The compiler is yelling at you because your char pointer (and your '0' and '9' chars) is being de-referenced and cast into an integer to use the <= operator. There should be some string/char comparison functions in the c standard library that you can use instead. *hint hint*.
So in my code above, it make sense that "" represents a char *. However, let say if I see a digit or a space, how would I represent an empty char? The following '' would not work since the compiler complains that it is an empty char.
My goal on that part of my code is to kind of "concatenate" (not the best word to explain my goal) the strings together. So that is produces the expected output. By putting an empty string where *s points at that moment allows the other strings to be pushed over.
I don't think so. Unless things have changed a lot since I learnt C many years ago you can use <= on chars.
One problem is in this line:
Code:if (('0' <= *s && *s <= '9') || *s == ' ') {
The compiler is yelling at you because your char pointer (and your '0' and '9' chars) is being de-referenced and cast into an integer to use the <= operator. There should be some string/char comparison functions in the c standard library that you can use instead. *hint hint*.
So in my code above, it make sense that "" represents a char *. However, let say if I see a digit or a space, how would I represent an empty char? The following '' would not work since the compiler complains that it is an empty char.
My goal on that part of my code is to kind of "concatenate" (not the best word to explain my goal) the strings together. So that is produces the expected output. By putting an empty string where *s points at that moment allows the other strings to be pushed over.
Use the code tags please.
Also, you should really think about properly indenting your code for greatly improved readability. Lastly, your error is a punctuation error. In C, what does "" represent ? What type is *s in your normalize function ?
Right there should tell you what you're doing wrong.
Also, you should rethink your function to remove the return statements, they are completely unneeded.
First of all, thanks for the person above who edited my code, since I just copy-and-paste my code from CodeRunner.![]()
That's completely untrue. If you'd bothered to copy/paste and compile his code, you'd know that is not the line the compiler complains about.
void normalize(std::string *s){
...
if (('0' <= *s && *s <= '9') || *s == ' ') {
...
}
You're welcome (only Moderators and Gods can edit other people's posts). If you post more code the [ code ]code here[ /code ] (without the spaces in the tags) tags should be used. I didn't need to edit/alter it apart from the tags: copy and paste seems fine.
Oh and I don't think "punctuation error" is really the correct terminology. You have a logic error in thinking you can set one of the characters in the string to be "blank" or "empty".
Oh and I don't think "punctuation error" is really the correct terminology.
That makes more sense. I've given it some thought and I think you just can't really place an "empty" string at that given spot where s is currently pointing at (the value I mean). So I'm guessing this requires looking "ahead" of the next characters and placing the next character found to the spot where I have encountered a digit or a space already.
char * removecharacteratindex(char * string, int index);