😸
[C] strtoul 関数
機能
文字列を符号なし長整数(unsigned long型)に変換する関数[1]
使用例
12345
と表示する
\n
は改行を表す エスケープシーケンス[2]
コード
printf("%lu\n", strtoul("12345", NULL, 10));
全文
#include <stdio.h>
#include <stdlib.h>
void main() {
printf("%lu\n", strtoul("12345", NULL, 10));
}
実行結果
12345
789
を変数から表示する
先頭の数字だけ コード
const char *s = "789xyz";
unsigned long n = strtoul(s, NULL, 10);
printf("%lu\n", n);
全文
#include <stdio.h>
#include <stdlib.h>
void main() {
const char *s = "789xyz";
unsigned long n = strtoul(s, NULL, 10);
printf("%lu\n", n);
}
実行結果
789
Discussion