Hi,
I'm trying to write a function that takes in a c-string, and remove all 'T' and 't' from the string.
So here's what I have so far, but every time I try to compile it, it gives an empty character constant error.
void removeT(char* msg)
{
char* ptr;
// Search for 't' and delete it
ptr = strchr(msg, 't');
while (ptr != NULL)
{
cerr << "found 't' at " << ptr-msg << endl;
*ptr = '';
ptr=strchr(ptr+1, 't');
}
// Search for 'T' and delete it
ptr = strchr(msg, 'T');
while (ptr != NULL)
{
cerr << "found 'T' at " << ptr-msg << endl;
*ptr = '';
ptr=strchr(ptr+1, 'T');
}
}
int main()
{
char msg[40] = "This stock price is near a bottom!";
removeT(msg);
cout << msg << endl; // Should print 'his sock price is near a boom!'
}
I tried replacing '' with "", but then it just gives me another error, saying it cannot convert 'const char' to 'char'.
I know instead of
*ptr='';
I can put
*ptr=' '; // Space between ''
but that will just a space, and print out the final msg as ' his s ock price is near a bo om!'
Is there any way to go around this? Thanks in advance!