#include <string.h>
#include <regex.h>

void rstrip( char* dest, const char* src ) {
  regex_t preg;
  regmatch_t pmatch;
  
  regcomp(&preg, "\\ +$", REG_EXTENDED|REG_NEWLINE);
  regexec(&preg, src, 1, &pmatch, 0);
  regfree(&preg);
  
  strncpy( dest, src, pmatch.rm_so );
}