=== 10. ライブラリ ====================

ANSIの標準ヘッダの一覧は以下の通り。それらを用いればより移植性の高いプログラムをかける。

  • assert.h
  • ctype.h
  • errno.h
  • float.h
  • limits.h
  • locale.h
  • math.h
  • setjmp.h
  • signal.h
  • stdarg.h
  • stddef.h
  • string.h
  • stdio.h
  • stdlib.h
  • time.h

ヘッダは、どのような順序で#includeしても構いません。また、同じ標準ヘッダを何度#includeしても構いません。

42の課題でよく使うヘッダ

  • stdio.h
  • stdlib.h
  • stddef.h
  • unistd.h
  • string.h

おすすめの関数(RTFM)

ctype.h

  • islower()
  • isupper()
  • isdigit()
  • isxdigit()
    • 16進数
  • isalpha()
  • isalnum()
  • isspace()
  • isprint()
  • isgraph()
    • space以外のprintableな文字
  • ispunct()
    • space, アルファベット以外
  • iscntrl()
    • 制御文字でtrue
  • tolower()
  • toupper()

limits.h

  • CHAR_BIT
  • INT_MIN, INT_MAX
  • UINT_MAX

stddef.h

  • NULL定数
    • NULLはどのオブジェクトも指さないポインタ定数
  • offsetof
  • size_t
  • uintptr_t

string.h

  • strlen()
  • strcpy(), strncpy(), strlcpy()
    • strlcpy()は、BSD拡張。Linuxで使うなら#include<bsd/string.h>cc -lbsd *.cが必要になる
  • strcat(), strncat(), strlcat()
  • strcmp(), strncmp()
  • strchr(), strrchr()
  • strspn(), strcspn(), strpbrk(), strtok()
  • strstr()
  • strtol()