未分類

C言語でchar文字列の長さを取得する (strlen)

投稿日:

strlen 関数を使って取得すればよい。
sizeof という関数もあるが、strlen と振る舞いが異なるので注意。

#include<stdio.h>
#include<string.h>

int main () {

char moji[100] = "good morning";

printf("strlen(moji)=%lu\n", strlen(moji));
printf("sizeof(moji)=%lu\n", sizeof(moji));

return 0;
}

結果

strlen(moji)=12
sizeof(moji)=100

-未分類

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

tex でインテグラルが小さくなる→大きくする方法

文章中でインテグラル(積分記号)を大きくするには、\displaystyle と書けばよい。 例 usual $\int \frac{ax+b}{cx+d} dx$display style $\di …

no image

tex で数式モード内に普通の文字列を入力する方法

\textrm を使う。 例 $$y = f (x) \hspace{1cm} \textrm{This is a function.}$$ 結果

no image

tex で、表のキャプション内で改行する方法

\newline を使って次のように書く。 例 \begin{table} \begin{tabular}{ |c|c|c|c| } \hline 1 & 2 & 3 \\ \hlin …

no image

tex で和集合を入力する方法

\bigcup を使う。 例 $\displaystyle \bigcup _ {i \in \Lambda} A_i $ 結果

no image

tex で脚注を表示する方法

\footnote を使う。 例 \footnote{this is a footnote.} 結果