Hi,
I am new to this forum.Can anybody please tell me how to remove end spaces (whitespaces) from a string.
Thank You,
Nitin
Printable View
Hi,
I am new to this forum.Can anybody please tell me how to remove end spaces (whitespaces) from a string.
Thank You,
Nitin
char *p;
while (*p != '\n') p++;
*p = '\0';
You can start from the last character of the string
then in the loop
check if it is whitespace
and if condition is true - put there '\0' character and move to the previous character.
if you find a non-whitespace character or get to the beginning of the string - you should exit the loop
Thank u very much for help.
Don't turn it in if you can't explain it.Code:int trim( char *s )
{
if( s )
{
if( !*s || (trim( s + 1 ) && isspace( *s )) )
{
*s = '\0';
return 1;
}
}
return 0;
}
Quzah.