Comment detail

末尾の空白文字を取り除く (Nested Flatten)

Cがなかったので。 正規表現でやると、こんな感じでしょうか。。。

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

Index

Feed

Other

Link

Pathtraq

loading...