Back to Blog
Back to Blog
Vugen: Will This Code Remove Trailing Spaces?
Posted on Jul, 2012 by Admin
Let’s have a little fun today – and hopefully I can get some interaction from you C Guru’s out there. How about something cryptic in C? Let’s say I wanted to remove some trailing spaces with as few lines of C code as possible. Will the example below work?
static char* rtrim( char* s)
{
int i;
if (s){i = strlen(s); while ((--i)>0 && isspace(s[i]) ) s[i]=0;}
return s;
};
Why or why not? Care to explain what this code is doing? Comments are open and welcome.