I have a string:
string s = "If you can't rhyme against the DARK SIDE of the force, why even bother! So many dudes been with your mom...who even knows if I'm your father";
My goal is to scan this string by setting a index variable to the first character in a word until a alphanumeric character is found. I initially used isalnum(); for this. If this returns true, then I would create another index variable for this position and continue scanning until I found a punctuation mark.
The assignment I am working on has also states that if I don't find a alphanumeric char then I must stop scanning.
There's also a note I am not quite understanding (mostly because I can't figure the code out. It is:
"At this point you have two index variables: the first one indicates the position of the first alphanumeric character and the second one indicates the position just after the last alphanumeric character. If the word does not have any alphanumeric characters, then both index values indicate the same position"
Can anyone help me understand how this should work?
for (int i = 0; i < s.size(); i++)
{
if (isalnum(s[i]))
for (int j = i; j <= i; j++)
{
if (ispunct(j))
s.erase(j);
}
}
This is just what I spitballed but I really can't understand how flow of logic is suppose to go. This is obviously non-sense. I haven't written too much of anything else because the whole program really relies on having this concept down. I'll need to copy the word without punct into a substr called s2 but yeah. This is all I have come up with.