strcspn() — 첫 번째 문자 일치의 오프셋 찾기
형식
#include <string.h>
size_t strcspn(const char *string1, const char *string2);
언어 레벨
ANSI
스레드세이프
예
로케일 감지
이 함수의 작동은 현재 로케일의 LC_CTYPE 범주로 영향을 받을 수 있습니다. 자세한 정보는 CCSID 및 로케일 이해의 내용을 참조하십시오.
설명
strcspn() 함수는 string2에 지정된 문자 세트에 속하는 string1에서 첫 번째 문자 표시를 찾습니다. 널 문자는 검색에서 고려되지 않습니다.
strcspn() 함수는 널로 끝나는 스트링에서 작동합니다. 함수에 대한 스트링 인수는 스트링 끝을 나타내는 널 문자(\0)를 포함해야 합니다.
리턴값
strcspn() 함수는 찾은 첫 번째 문자의 색인을 리턴합니다. 이 값은 string2에 없는 문자로 모두 구성된 string1의 초기 서브스트링 길이와 같습니다.
예
이 예는 strcspn()을
사용하여 string에서
문자 "a", "x", "l"
또는 "e"의 첫 번째 표시를 찾습니다.
#include <stdio.h>
#include <string.h>
#define SIZE 40
int main(void)
{
char string[SIZE] = "This is the source string";
char * substring = "axle";
printf( "The first %i characters in the string \"%s\" "
"are not in the string \"%s\" \n",
strcspn(string, substring), string, substring);
}
/********** Output should be similar to: **************
The first 10 characters in the string "This is the source string"
are not in the string "axle"
*/