I am to write a program that will drop a certain character from a string.
Such as with the string "hi hun" I want the h to be dropped thus "i un". I'd also like to do it for uppercase letters as well. Here is my attempt thus far, only focusing on getting one case to drop rather than an uppercase as well.
The output I recieve is in all h'
const int MAX = 80;
cout << "Enter a message: " << endl;
cout << message << endl;
char remove(char mes)
for(int i = 0; mes[i] != '\0'; i++)
if (mes[i] = 'h')
(mes[i] - 'h' + ' ');
if (mes[i] = 'h') should be if (mes[i] == 'h'). = is assignment, == is comparison.
> if (mes[i] = 'h')
You mean == for comparison, this is an assignment at present.
In your if statement you want to use == (comparison) instead of = (assignment). And the line after that doesn't really do anything--you could just assign a space there.
But if you don't want extra spaces you'd have to do a bunch of shifting of array elements which could be slightly difficult.
Ah I feel silly.
I went back and changed it. It fixed the hhhh thing but it's still not removing the character h from the string. Basically i'm putting it in and its coming back to me the same.
Thanks for the input thus far.
what you could try, is instead of simply assigning a space, is if it doesn't match the char you want to remove, you copy the character over to the new char array, other wise you simply skip it.