wcsncpy() - ワイド文字ストリングのコピー

標準

標準/拡張機能 C/C++ 依存項目

ISO C 改訂
XPG4
XPG4.2
C99
Single UNIX Specification、バージョン 3

両方  

形式

#include <wchar.h>

wchar_t *wcsncpy(wchar_t * __restrict__string1, 
                 const wchar_t * __restrict__string2, size_t count);

機能説明

string2 から string1 間の 最大 count ワイド文字までをコピーします。string2count 文字より短い 場合には、string1 は NULL ワイド文字を使用して count 文字まで引き伸ばされます。wcsncpy() 関数は、NULL 文字で終了するワイド文字ストリングを操作します。この関数に対するストリング引数には、ストリングの終わりにマークを 付ける NULL ワイド文字が入っていなければなりません。

このワイド文字関数の動作は、現行ロケールの LC_CTYPE カテゴリーの影響を受けます。 カテゴリーを変更すると、未定義の結果が発生する可能性があります。

戻り値

wcsncpy() は string1 を戻します。

CELEBW15
⁄* CELEBW15                                      

   This example demonstrates the difference between &wcscpy. and &wcsncpy..     
                                                                                
 *⁄                                                                             
#include <stdio.h>                                                              
#include <wchar.h>                                                              
                                                                                
#define SIZE    40                                                              
                                                                                
int main(void)                                                                  
{                                                                               
  wchar_t source[ SIZE ] = L"123456789";                                        
  wchar_t source1[ SIZE ] = L"123456789";                                       
  wchar_t destination[ SIZE ] = L"abcdefg";                                     
  wchar_t destination1[ SIZE ] = L"abcdefg";                                    
  wchar_t * return_string;                                                      
  int    index = 5;                                                             
                                                                                
  ⁄* This is how wcscpy works *⁄                                                
  printf( "destination is originally = '%ls'¥n", destination );
  return_string = wcscpy( destination, source );                                
  printf( "After wcscpy, destination becomes '%ls'¥n¥n", destination );
                                                                                
  ⁄* This is how wcsncpy works *⁄                                               
  printf( "destination1 is originally = '%ls'¥n", destination1 );
  return_string = wcsncpy( destination1, source1, index );                      
  printf( "After wcsncpy, destination1 becomes '%ls'¥n", destination1 );
}                                                                               
出力:
destination is originally = 'abcdefg'
After wcscpy, destination becomes '123456789'

destination1 is originally = 'abcdefg'
After wcsncpy, destination1 becomes '12345fg'

関連情報