=================================================================== ==============================트리밍 기능이 제대로 작동하지 않는 이유를 알 수 없음
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 ' :'을 위의 기능이 공백을 제거하고 나에게 반환하도록되어
'819, .
대신에, 나는 다시 무엇을 얻을 :
'ABCDEF /'
어떤 아이디어?
참고 : 따옴표는 공백이 원래 문자열에 있음을 나타냅니다.
감사합니다! 나는 이것을 극복하고 있었다.나는 이것을 "end - front + 1"로 바꾸었다. 물론, 나는 끝 - 정면 + 1이 내가 목적지 인 최대 길이보다 작음을 확인하고있다. – Sagar