Suppose I have a char* word = "abaradasaddragfavvdavgasbga00rarcrawabr0ac0ra0ra0vra0"
and I want to remove all the '0' chars
from the word
, in place, without using extra-memory or memmove
. How could I do it?
So the output would be: "abaradasaddragfavvdavgasbgararcrawabracraravra"
** What I have tried **:
void removeZeros( char* word) {
int size = strlen( word );
int i;
for( i = 0; i < size; i++ ){
if( word[i] == '0' ){
word[ i ] = word[ i + 1 ];
i++;
}
}
}
* Rules **:
- should be done in place
- should not call any built-in function like
memmove
orremove
- should not use extra-memory
- should not assign it to another variable