Hey guys,
I have a couple of quick questions, Iv searched the forums and the internet and found a not very much on removing an array element. If you could guide me to a website or a book with information on char arrays it would be helpful.
My second question is this, I have a char array shown in code below and I want to remove spaces from the array. For example I have and array
char arr[] = {'a', 'b', 'c', ' ', ' ', ' ', ' ', ' ', 'd', 'e', 'f', '\0'};
How can I make it so that all the space from arr[4] to arr[7] are removed?
Below is the code I have tried, Im running a loop to go through the array and then when it hits a space search the next element to see if that is a space as well. If it is I want to copy all the remaining elements into the next space and repeat the loop.
I understand that you can't give code so I don't expect any just a little heading so I can figure out what Im doing wrong or not doing at all.
for(int i = 0; i <= x; i++)
{
if(arr[i] == ' '){
if(arr[i + 1] == ' '){
for(int j = i; j <= x; j++){
arr[i] = arr[i + 1];
}
}
//causes all values to be removed from the back of array
//x--;
}
}