How do I remove a character from character array?

This is a discussion on How do I remove a character from character array? within the C++ Programming forums, part of the General Programming Boards category; I am tryin gto make a program that allows the user to enter a string as a character array and ...

How do I remove a character from character array?

I am tryin gto make a program that allows the user to enter a string as a character array and a letter to delete from the array. I am having a very hard time deleting the letter from the array. The word can not have a space where the letter used to be. So if the user enters "hello world" and the letter 'l'. It should print "heo word". Can someone please point me in the right direction here? Thanks

But I need to print the string in main, not in the remove() function. So I was thinking of using strcpy, to try and copy all letters except the specified letter into a new character array. Is this possible? I looked up strcpy and found no one is using it like I'm trying to, but maybe there is good reason for that?

As I recall, you can't use strcpy on "overlapping" things (i.e, if the source and destination are in the same place in memory). memmove might work in that respect. I would still suggest shifting the whole thing over yourself, though.

If you have to delete character 4:
Put character 5 in the 4th spot.
Put character 6 in the 5th spot.
Put character 7 in the 6th spot.
Put character 8 in the 7th spot.
.
.
.
Put character (last) in the (last-1)th spot.

Presumably you'll do that in a loop. Since it's a string, once you reach the \0 character you are done.

If you have to delete character 4:
Put character 5 in the 4th spot.
Put character 6 in the 5th spot.
Put character 7 in the 6th spot.
Put character 8 in the 7th spot.
.
.
.
Put character (last) in the (last-1)th spot.

Presumably you'll do that in a loop. Since it's a string, once you reach the \0 character you are done.

This will work with the way my program is set up now? Also, this will work if I have to delete character 4, 5, and 11?

I am pointing out that you ought to post some code instead of asking questions about a random statement you think could be right or wrong. If you seriously have no idea what to do, then you haven't been paying attention, either. Try writing what you think you should do, based on what you've been told, because to be honest, it's very hard to show you more of the algorithm without giving you an implementation.

Isn't there a way that I can store all of the letters that are != to letter into another char array? That is what I was hoping to do with strcpy.

If you find all the instances of letter, then that should break up the cstring into sections that you can copy to another destination (as in, not cstring) with strncpy.