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