Go4Expert (http://www.go4expert.com/)
-   Programming (http://www.go4expert.com/forums/programming-forum/)
-   -   Char array insertion HELP! (http://www.go4expert.com/forums/char-array-insertion-help-t6599/)

TheMiz19 29Sep2007 03:13

Char array insertion HELP!
What would be the code, in C++, to insert or delete a char from an array:

for example:

char word[] = {'h','e','l','l','o'};

and say you want to delete 2-3. So you tell it to delete that and you get "heo"

how would you go about doing that or, what would be the code...thanks

DaWei 30Sep2007 22:04

Re: Char array insertion HELP!
You can't actually delete elements of an array in C/C++. You would need to move the 'o' up to the position of the first 'l'. You then need to know the size of the result. Your particular implementation makes that difficult, as it is not a C string, but merely an array of char. Had you declared it as a C string, it would have a nul terminator. Then, after moving the 'o' up, you could follow it with a terminator.

Your best bet here is to forgo a simple array and use something else. In this case a string class string would work very well. For non-textual material a vector (or similar) from the STL would do the trick. These objects can shrink and grow as you manipulate them.

All times are GMT +5.5. The time now is 12:18.