strlenを使って文字列の長さを見つける方法


C言語でStrlenを使った文字列の長さを見つけるためのチュートリアル
  • 関数は、与えられた文字列の文字数を数え、長い符号なし整数値を返します.
  • ヘッダーファイル内のC標準ライブラリで定義されています.
  • char saying[] = "Better late than never";
    strlen(saying);
    
  • NULL文字が遭遇したときにカウントを停止します.Cでは、NULL文字は文字列の末尾と見なされます.

  • 実施例
    #include <string.h>
    #include <stdio.h>
    
    int main()
    {
        char planet[] = "Earth";
    
        printf("\n Using strlen for planet without null character: %zu", strlen(planet));
        printf("\n Using sizeof for planet with null character: %zu", sizeof(planet));
    
        return 0;
    }
    

    出力
    Using strlen for planet without null character: 5
    Using sizeof for planet with null character: 6
    
    strlen()関数がNULL文字<string.h>に対してカウントされず、strlen()関数が実行されます.
    我々のサイトFind the length of a string using strlen() in Cの上で完全なポストを読んでください
    我々のサイトMeshWorldの上で他のポストを読んでください
    ハッピー😄 コーディング
    With ❤️ から🇮🇳