I have a problem with this function. I'm trying to eliminate blank spaces at the end of a char * pointer.
Something like this:
char *ptr = "Soy un puntero dinámico y me sobran espacios al final ";
With the difference that this is static and the one I am driving is dynamic.
I was doing this function for it but for some reason I can not see, the while is not working for me, meaning that the value of c is c = 0; when it should be higher.
char *quita_espacios_al_final(char **s)
{
char *p = *s;
if(p==NULL)return NULL;
unsigned int i=strlen(p);
unsigned int k=i;
unsigned int c=0;
while( *(p+i)==' ' && i>0)
{
i--;
c++;
}
char *tmp = new char [k-c+1];
for(unsigned int j=0; j<k-c; j++)
*(tmp+j)=*(p+j);
delete [] p;
return tmp;
}
Any idea why it does not work? o Another alternative to count the blank spaces at the end of the chain? PS: I do not care if it's in C or in C ++ while it's working, but the guy can not change it, it has to be (char *).