Hi,
I am new to this forum.Can anybody please tell me how to remove end spaces (whitespaces) from a string.
Thank You,
Nitin
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
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
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.
Hope is the first step on the road to disappointment.