산하님의 [wiki:토큰추출하기]를 조각코드 모음으로 옮겼습니다.
strsep이나 strtok 같은 토큰 추출 함수를 만들어본다. 기존의 표준함수들은 메모리를 할당하며 포인터를 반환하는데 이것이 언제 해제되는지 알 수 없다. (물론, glibc소스를 보면된다.) 소스는 보지 않았지만 대략, 사용자가 직접 해제해야 할 것 같아 보인다. 또한, 둘다 man을 보면 주의가 보인다. 그래서, 용도에 맞고 더 좋은(내가 보기에) 함수를 만들어 사용한다.
strsep의 NOTES :
The strsep() function was introduced as a replacement for strtok(), since the latter cannot
handle empty fields. However, strtok() conforms to ANSI-C and hence is more portable.
strtok의 BUGS :
Never use these functions. If you do, note that:
These functions modify their first argument.
These functions cannot be used on constant strings.
The identity of the delimiting character is lost.
The strtok() function uses a static buffer while parsing, so it's not thread safe.
Use strtok_r() if this matters to you.
설명
사용방법
코드
변경사항
2004/01/08
Recent Posts
Archive Posts
Tags