  | 
≫  | 
 | 
  
 | 
    
      | 
    
    
    
     
HP OpenVMS HP C ランタイム・ライブラリ・リファレンス・マニュアル (下巻)
  
 
  
 ワイド文字列の中の文字を,ワイド文字のセットと比較します。関数は,ワイド文字のセットに含まれていない文字だけからなる先頭の部分文字列の長さを返します。
 
 
形式
#include <wchar.h>
size_t wcscspn (const wchar_t *wstr1, const wchar_t *wstr2);
 
  
 
引数
 
 wstr1null で終了するワイド文字列へのポインタ。これが null 文字列だった場合には 0 が返されます。
 
 wstr2関数が探すワイド文字のセットを含んでいる, null で終了するワイド文字列へのポインタ。
 
 
説明
wcscspn関数は, wstr1 がポイントする文字列の中のワイド文字を, 
wstr2 に含まれている文字を検出するまでスキャンします。関数は,wstr2 に含まれていない文字のみから構成される, 
wstr1 の先頭のセグメントの長さを返します。
 
 
戻り値
 
  
 
例
 
 
#include <stdlib.h> 
#include <stdio.h> 
#include <wchar.h> 
#include <string.h> 
 
/* This test sets up 2 strings, buffer and w_string, and */ 
/* then uses wcscspn() to calculate the maximum segment  */ 
/* of w_string, which consists entirely of characters    */ 
/* NOT from buffer.                                      */ 
 
#define BUFF_SIZE 20 
#define STRING_SIZE 50 
 
main() 
{ 
    wchar_t buffer[BUFF_SIZE]; 
    wchar_t w_string[STRING_SIZE]; 
    size_t result; 
 
    /* Initialize the buffer */ 
 
 
    if (mbstowcs(buffer, "abcdefg", BUFF_SIZE) == (size_t)-1) { 
 
        perror("mbstowcs"); 
        exit(EXIT_FAILURE); 
    } 
 
    /* Initialize the string */ 
 
    if (mbstowcs(w_string, "jklmabcjklabcdehjklmno", STRING_SIZE) 
 
        == (size_t)-1) { 
 
        perror("mbstowcs"); 
        exit(EXIT_FAILURE); 
    } 
 
/* Using wcscspn - work out the largest string in w_string */ 
/* which consists entirely of characters NOT from buffer   */ 
 
    result = wcscspn(w_string, buffer); 
    printf("Longest segment NOT found in w_string is: %d", result); 
 
} 
 |  
 
  
この例のプログラムを実行すると,次の結果が生成されます。
 
 
 
Longest segment NOT found in w_string is: 4 
 
 |  
 
 
 
 
      |