void empty_spaces(char array[]){
int j=0,i=0,n=0;
n=strlen(array);
while(i<n){
if(array[i]==' '){
j=i;
while(j<n){
array[j]=array[j+1];
++j;
}
--n;
}else
++i;
}
if(n>15)
n=15;
array[n]='\0';
}
Could someone explain me, this code? This function cleans up the empty spaces in array, but could someone explain me exactly what it works?
It loops over every character in the array, removing all ‘ ‘ (space) characters. The inner loop is what does the erasing. When the outer loop finds a space character, the inner loop “shifts” the rest of the array to the left one index, overwriting the space.