Hi all,
I am using the following function which I found online to trim the leading and trailing whitespaces from a passed in string. It works fine for all the cases but I am having trouble in understanding the process being a newbie to C world.
char *trim (char *str)
{
char *ibuf, *obuf;
if (str)
{
for (ibuf = obuf = str; *ibuf; )
{
while (*ibuf && (isspace (*ibuf)))
ibuf++;
if (*ibuf && (obuf != str))
*(obuf++) = ' ';
while (*ibuf && (!isspace (*ibuf)))
*(obuf++) = *(ibuf++);
}
*obuf = '\0';
}
return (str);
}
Could someone please explain the above logic in detail.
Thanks ,
Scott.