Linux系统C函数简记

ANSI C是C语言标准库,GNU C函数库(又称为glibc)是Linux上最常用的实现,相比标准库做了扩展。

ANSI C标准库函数

  1. <assert.h>

  2. <complex.h>

  3. <ctype.h>

  4. <errno.h>

  5. <fenv.h.h>

  6. <inttypes.h>

  7. <local.h>

  8. <math.h>

  9. <setjmp.h>

  10. <signal.h>

  11. <stdarg.h>

  12. <stdbool.h>

  13. <stddef.h>

  14. <stdint.h>

  15. <stdio.h>

  16. <stdlib.h>

  17. <string.h>

  18. <tgmath.h>

  19. <time.h>

  20. <wchar.h>

  21. <wctype.h>

  • <ctype.h>:包含用来测试某个特征字符的函数的函数原型,以及用来转换大小写字母的函数原型;

isalnum

是否为字母数字

isalpha

是否为字母

islower

是否为小写字母

isupper

是否为大写字母

isdigit

是否为数字

isxdigit

是否为16进制数字

iscntrl

是否为控制字符

isgraph

是否为图形字符(例如,空格、控制字符都不是)

isspace

是否为空格字符(包括制表符、回车符、换行符等)

isblank

是否为空白字符(C99/C++11新增)(包括水平制表符)

isprint

是否为可打印字符

ispunct

是否为标点

tolower

转换为小写

toupper

转换为大写

  • <math.h>:包含数学库函数的函数原型;

sin

正弦

cos

余弦

tan

正切

modf

是否为拆分整数和小数部分字母

log

以e为底的对数

log10

以10为底的对数

pow

计算x的y次幂

exp

求取自然数e的幂

sqrt

开平方根

ceil

取上整

floor

取下整

fabs

绝对值

  • <stdio.h>:包含标准输入输出库函数的函数原型,以及他们所用的信息;

  • <stdlib.h>:包含数字转换到文本,以及文本转换到数字的函数原型,还有内存分配、随机数字以及其他实用函数的函数原型;

calloc

分配内存

free

释放内存

malloc

分配内存

realloc

修改分配内存

rand

随机数0到32767

abort

异常终止一个进程

exit

程序中止执行

getenv

获取环境变量

putenv

设置环境变量

labs

长整型参数的绝对值

atof

将字符串转换成一个双精度数

atoi

将字符串转换成一个整数

atol

将字符串转换成一个长整数

ecvt(fcvt)

将浮点数转换为字符串

  • <string.h>:包含字符串处理函数的函数原型;

strlen

求字符串长度

strcmp

比较2个字符串是否一样

strcat

字符串连接操作

strcpy

字符串拷贝操作

strchr

查询字符串位置

strstr

查询子串

  • <time.h>:包含时间和日期操作的函数原型和类型;

这个太常用了。
struct tm {
   int tm_sec;         /* 秒,范围从 0 到 59        */
   int tm_min;         /* 分,范围从 0 到 59        */
   int tm_hour;        /* 小时,范围从 0 到 23        */
   int tm_mday;        /* 一月中的第几天,范围从 1 到 31    */
   int tm_mon;         /* 月,范围从 0 到 11        */
   int tm_year;        /* 自 1900 年起的年数        */
   int tm_wday;        /* 一周中的第几天,范围从 0 到 6    */
   int tm_yday;        /* 一年中的第几天,范围从 0 到 365    */
   int tm_isdst;       /* 夏令时                */
};

asctime

求字符串长度

clock

返回程序执行起时间

ctime

返回当地时间

difftime

返回 time1 和 time2 之间相差的秒数

gmtime

把日期和时间转换为UTC

localtime

返回本地时间

mktime

返回指针描述的时间

strftime

格式化时间

time

获取当前时间

GLIBC额外的库函数

  • <unistd.h>
  • <fcntl.h>
  • <malloc.h>
  • <alloca.h>
  • <pwd.h>
  • <shadow.h>
  • <ftw.h>
  • <pthread.h>
  • <utmpx.h>
  • <paths.h>
  • <dlfcn.h>
  • <termios.h>
  • <poll.h>

还有一些系统函数

  • <sys/socket.h>
  • <sys/types.h>
  • <sys/stat.h>
  •  <sys/time.h>
  • <sys/select.h>

猜你喜欢

转载自blog.csdn.net/huntenganwei/article/details/127753548
今日推荐