================================================== =============================
void trim(const char * orig, char * dest)
{
size_t front = 0;
size_t end = sizeof(orig) - 1;
size_t counter = 0;
char * tmp = null;
if (sizeof(orig) > 0)
{
memset(dest, '\0', sizeof(dest));
/* Find the first non-space character */
while (isspace(orig[front]))
{
front++;
}
/* Find the last non-space character */
while (isspace(orig[end]))
{
end--;
}
tmp = strndup(orig + front, end - front + 1);
strncpy(dest, tmp, sizeof(dest) - 1);
free(tmp); //strndup automatically malloc space
}
}
================================================== =============================
私は文字列を持っています:
'ABCDEF / G01'
上記の関数は、スペースを削除して私に戻ることになっています。
'ABCDEF/G01'。
代わりに、私が返すのは次のとおりです。
「ABCDEF/」
何か案は?
注:引用符は、元の文字列にスペースが存在することを示すためのものです。