1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#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 );
}