#include <stdio.h>
#include <ctype.h>

/*
**  Remove leading, trailing, & excess embedded spaces
**
**  public domain by Bob Stout & Michael Dehlwes
*/

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);
}

char *strupr(char *string)
{
   char *s;

   if (string)  {
       for (s = string; *s; ++s)
           *s = toupper(*s);
   }
   return string;
}