Desc :
char *strtok(char * strToken, const char *strDelimit);
strToken - 원본 문자열
strDelimit - 구분 문자, 문자 세트
구분문자 발견 --> 구분 문자 자리에 null을 넣은 후 문자열의 선두 번지 반환
내부적으로 이전에 검색한 위치를 저장하고 있다. null을 함수에 넘겨주면 검색된 다음 위치부터 자동으로 검색
일치문자 없음 --> 문자열의 선두번지 반환
Source Code :
#include <stdio.h>
#include <string.h>
void main()
{
char string[] = "a12, b34, c56";
char *token;
token = strtok(string, ", "); //,(공백)
while (token)
{
puts(token);
token = strtok(NULL, ", ");
}
}
Result :
'C' 카테고리의 다른 글
[C] 218 문자열에서 숫자추출 isdigit (1) | 2021.02.06 |
---|---|
[C] 217 문자열에서 알파벳만 분리하기 strtok (1) | 2021.02.06 |
[C] 215 문자열에서 인덱스구하기 strstr() (1) | 2021.02.06 |
[C] 214 (비트연산) 나눗셈 구현 (1) | 2021.02.06 |
[C] 213 (비트연산) 곱셈 구현 (1) | 2021.02.06 |