文字列の長さを調べるstrlen関数のサンプルコードを以下に記します。
c-top.html is not found or not readable.strlen関数を使用する場合、string.hをインクルードする必要があります。
#include <stdio.h> #include <string.h> int main(void) { int n1, n2; char *s1 = "Hello World!"; char *s2 = "IT SUPPORT SAKURA"; n1 = strlen(s1); n2 = strlen(s2); printf("n1 = %d\n", n1); printf("n2 = %d\n", n2); return 0; }
上記の実行結果は以下の通りです。
$ gcc strlen.c -o strlen $ ./strlen n1 = 12 n2 = 17
以上、strlen関数のサンプルコードでした。
c-btm.html is not found or not readable.