  | 
≫  | 
 | 
  
 | 
    
      | 
    
    
    
     
HP OpenVMS HP C ランタイム・ライブラリ・リファレンス・マニュアル (下巻)
  
 
  
 1 つの文字列の一定数のワイド文字を別の文字列に連結します。
 
 
形式
#include <wchar.h>
wchar_t *wcsncat (wchar_t *wstr_1, const wchar_t *wstr_2, size_t maxchar);
 
  関数バリアント
wcsncat関数は,それぞれ 32 ビットと 64 ビットのポインタ・サイズで使用するための
_wcsncat32と
_wcsncat64という名前のバリアントを持っています。ポインタ・サイズ固有の関数の使用方法については,『HP C ランタイム・ライブラリ・リファレンス・マニュアル(上巻)』第 1.9 節を参照してください。
 
引数
 
 wstr_1, wstr_2null で終了するワイド文字列へのポインタ。
 
 maxchar
wstr_2 から wstr_1 にコピーされるワイド文字の数の最大値。maxchar が 0 の場合, wstr_2 から文字はコピーされません。
 
 
説明
wcsncat関数は,ワイド文字列 wstr_2 から wstr_1 の末尾に,最高 
maxchar 個のワイド文字を追加します。
wcsncat関数の結果には,終端の null ワイド文字がつねに追加されます。このため,wstr_1 に格納されるワイド文字の数の最大値は
wcslen(wstr_1) + maxchar + 1) です。
wcscatも参照してください。
  
 
戻り値
 
| x
 | 
連結された結果を保持できるだけの大きさを持つと仮定される第 1 引数
wstr_1。
 | 
 
 
  
 
例
 
 
#include <stdlib.h> 
#include <stdio.h> 
#include <wchar.h> 
#include <string.h> 
 
/* This program concatenates two wide-character strings using   */ 
/* the wcsncat function, and then manually compares the result  */ 
/* to the expected result                                       */ 
 
#define S1LENGTH 10 
#define S2LENGTH 8 
#define SIZE     3 
 
main() 
{ 
    int i; 
    wchar_t s1buf[S1LENGTH + S2LENGTH]; 
    wchar_t s2buf[S2LENGTH]; 
    wchar_t test1[S1LENGTH + S2LENGTH]; 
 
    /* Initialize the three wide-character strings */ 
 
 
    if (mbstowcs(s1buf, "abcmnexyz", S1LENGTH) == (size_t)-1) { 
 
        perror("mbstowcs"); 
        exit(EXIT_FAILURE); 
    } 
 
 
    if (mbstowcs(s2buf, " orthis", S2LENGTH) == (size_t)-1) { 
 
        perror("mbstowcs"); 
        exit(EXIT_FAILURE); 
    } 
 
    if (mbstowcs(test1, "abcmnexyz orthis", S1LENGTH + SIZE) 
 
        == (size_t)-1) { 
 
        perror("mbstowcs"); 
        exit(EXIT_FAILURE); 
    } 
 
/* Concatenate s1buf with SIZE characters from s2buf, */ 
/* placing the result into s1buf. Then compare s1buf  */ 
/* with the expected result in test1.                 */ 
 
    wcsncat(s1buf, s2buf, SIZE); 
 
    for (i = 0; i <= S1LENGTH + SIZE - 2; i++) { 
        /* Check that each character is correct */ 
        if (test1[i] != s1buf[i]) { 
            printf("Error in wcsncat\n"); 
            exit(EXIT_FAILURE); 
        } 
 
    } 
 
    printf("Concatenated string: <%S>\n", s1buf); 
} 
 |  
 
 この例のプログラムを実行すると,次の結果が生成されます。
 
 
 
Concatenated string: <abcmnexyz or> 
 
 |  
 
  
 
 
      |