strlen() - ストリング長の判別

標準

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

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

両方  

形式

#include <string.h>

size_t strlen(const char *string);

機能説明

strlen() 組み込み関数によって、終了 NULL 文字を除く 、string で示されるストリングの長さが判別されます。

戻り値

strlen() は、string の長さを戻します。

CELEBS43
⁄* CELEBS43                                      

   This example determines the length of the string that is                     
   passed to main.                                                              
                                                                                
 *⁄                                                                             
#include <stdio.h>                                                              
#include <string.h>                                                             
                                                                                
int main(int argc, char **argv)                                                 
{                                                                               
                                                                                
  if ( argc != 2 )                                                              
    printf( "Usage: %s string¥n", argv[0] );
  else                                                                          
    printf( "Input string has a length of %i¥n", strlen( argv[1] ));
}                                                                               

出力

入力が次のストリング "How long is this string?" の場合、想定される出力は次のようになります。
Input string has a length of 24

関連情報