C语言函数手册

# C语言函数手册

# 1 字符检测

函数 说明
isascii() (opens new window) 判断字符是否为ASCII码字符

# 2. 字符串操作

函数 说明
gcvt() (opens new window) 将浮点型数转换为字符串(四舍五入)
index() (opens new window) 查找字符串并返回首次出现的位置
rindex() (opens new window) 查找字符串并返回最后一次出现的位置
strcasecmp() (opens new window) 判断字符串是否相等(忽略大小写)
strcpy() (opens new window) 复制字符串
strdup() (opens new window) 复制字符串
strncasecmp() (opens new window) 比较字符串的前n个字符

# 3. 内存管理函数

函数 说明
getpagesize() (opens new window) 取得内存分页大小
mmap() (opens new window) 建立内存映射
munmap() (opens new window) 解除内存映射
memccpy() (opens new window) 复制内存中的内容
memchr() (opens new window) 在内存中查找特定字符
memcmp() (opens new window) 比较内存前n个字节

# 4. 日期时间函数

函数 说明
asctime() (opens new window) 将时间日期以字符串格式表示
ctime() (opens new window) 将时间日期以字符串格式表示
gettimeofday() (opens new window) 获取当前时间
gmtime() (opens new window) 获取当前时间和日期
localtime() (opens new window) 获取当前时间和日期并转换为本地时间
mktime() (opens new window) 将时间转换成经过的秒数
settimeofday() (opens new window) 设置当前时间戳
time() (opens new window) 获取当前时间(以秒数表示)

# 5. 数学函数

函数 说明
abs() (opens new window) 求绝对值(整数)
asin() (opens new window) 求反正弦的值(以弧度表示)
atan() (opens new window) 求反正切的值(以弧度表示)
atan2() (opens new window) 求反正切的值(以弧度表示)
ceil() (opens new window) 向上取整

# 6. 文件操作函数

函数 说明
endgrent() (opens new window) 关闭文件(关闭组文件)
endpwent() (opens new window) 关闭文件(关闭密码文件)
endutent() (opens new window) 关闭文件(关闭utmp文件)
fgetgrent() (opens new window) 读取组格式函数
fgetpwent() (opens new window) 读取密码格式
getegid() (opens new window) 获得组识别码
geteuid() (opens new window) 获取用户识别码函数
getgid() (opens new window) 取得组识别码函数
getgrent() (opens new window) 从组文件中取得账号的数据
getgrgid() (opens new window) 从组文件中取得指定gid的数据
getgrnam() (opens new window) 从组文件中取得指定组的数据
getgroups() (opens new window) 获取组代码函数
getpw() (opens new window) 取得指定用户的密码文件数据
getpwent() (opens new window) 从密码文件中取得账号的数据
getpwnam() (opens new window) 从密码文件中取得指定账号的数据
getpwuid() (opens new window) 从密码文件中取得指定uid的数据
getuid() (opens new window) 取得真实的用户识别码
getutent() (opens new window) 从utmp文件中取得账号登录数据
getutid() (opens new window) 从utmp文件中查找特定的记录
getutline() (opens new window) 文件查找函数(从utmp文件中查找特定的
initgroups() (opens new window) 初始化组清单
pututline() (opens new window) 将utmp记录写入文件
seteuid() (opens new window) 设置有效的用户识别码
setfsgid() (opens new window) 设置文件系统的组识别码
setfsuid() (opens new window) 设置文件系统的用户识别码
setgid() (opens new window) 设置真实的组识别码
setgrent() (opens new window) 从头读取组文件中的组数据
setgroups() (opens new window) 设置组代码函数
setpwent() (opens new window) 从头读取密码文件中的账号数据
setregid() (opens new window) 设置真实及有效的组识别码
setreuid() (opens new window) 设置真实及有效的用户识别码
setuid() (opens new window) 设置真实的用户识别码
setutent() (opens new window) 从头读取utmp文件中的登录数据
utmpname() (opens new window) 设置文件路径
close() (opens new window) 关闭文件
creat() (opens new window) 创建文件函数
dup() (opens new window) 复制文件描述词
dup2() (opens new window) 复制文件描述词
fcntl() (opens new window) 文件描述词操作函数
flock() (opens new window) 解除锁定文件
fsync() (opens new window) 将缓冲区数据写回磁盘
lseek() (opens new window) 移动文件的读写位置
mkstemp() (opens new window) 建立临时文件
open() (opens new window) 打开文件函数
read() (opens new window) 读文件函数(由已打开的文件读取数据)
sync() (opens new window) 写文件函数(将缓冲区数据写回磁盘)
write() (opens new window) 写文件函数
clearerr() (opens new window) 清除文件流的错误旗标
fclose() (opens new window) 关闭打开的文件
fdopen() (opens new window) 将文件描述词转为文件指针
feof() (opens new window) 检查文件流是否读到了文件尾
fflush() (opens new window) 更新缓冲区
fgetc() (opens new window) 读文件函数(由文件中读取一个字符)
fgets() (opens new window) 读取文件字符串
fileno() (opens new window) 获取文件流所使用的文件描述词
fputc() (opens new window) 写文件函数(将一指定字符写入文件流中)
fputs() (opens new window) 写文件函数(将一指定的字符串写入文件
fread() (opens new window) 读文件函数(从文件流读取数据)
freopen() (opens new window) 打开文件函数,并获得文件句柄
fseek() (opens new window) 移动文件流的读写位置
ftell() (opens new window) 取得文件流的读取位置
fwrite() (opens new window) 写文件函数(将数据流写入文件中)
mktemp() (opens new window) 产生唯一临时文件名
setbuffer() (opens new window) 设置文件流的缓冲区
setlinebuf() (opens new window) 设置文件流为线性缓冲区

# 7. 进程操作函数

函数 说明
atexit() (opens new window) 设置程序正常结束前调用的函数
execl() (opens new window) 执行文件函数
execlp() (opens new window) 从PATH 环境变量中查找文件并执行
execv() (opens new window) 执行文件函数
execve() (opens new window) 执行文件函数
execvp() (opens new window) 执行文件函数
exit() (opens new window) 结束进程
_exit() (opens new window) 结束进程执行
getpgid() (opens new window) 获取进程组识别码
getpgrp() (opens new window) 获取进程组识别码
getpid() (opens new window) 获取进程识别码
getppid() (opens new window) 取得父进程的进程识别码
getpriority() (opens new window) 取得程序进程执行优先权
nice() (opens new window) 改变进程优先顺序
on_exit() (opens new window) 设置程序正常结束前调用的函数
setpgid() (opens new window) 设置进程组识别码函数
setpgrp() (opens new window) 设置进程组识别码
setpriority() (opens new window) 设置程序进程执行优先权
system() (opens new window) 执行shell命令
wait() (opens new window) 结束(中断)进程函数(常用)
waitpid() (opens new window) 中断(结束)进程函数(等待子进程中断或
fprintf() (opens new window) 输出函数(格式化输出数据至文件)
fscanf() (opens new window) 输入函数(比较常用)
sacnf() (opens new window) 字符串输入函数(最常用的输入函数)
vfprintf() (opens new window) 输出函数(格式化输出数据至文件)
vfscanf() (opens new window) 输入函数(先格式化字符串再输入)
vprintf() (opens new window) 输出函数
vscanf() (opens new window) 字符串格式化输入函数
vsprintf() (opens new window) 格式化字符串
vsscanf() (opens new window) 字符串输入函数
vfork() (opens new window) 建立新的进程

# 8. 文件权限控制函数

函数 说明
access() (opens new window) 判断是否具有存取文件的权限
alphasort() (opens new window) 依字母顺序排序目录结构
chdir() (opens new window) 改变当前的工作目录
chmod() (opens new window) 修改文件权限
chown() (opens new window) 改变文件所有者
chroot() (opens new window) 改变文件根目录
closedir() (opens new window) 关闭目录
fchdir() (opens new window) 改变当前工作目录
fchmod() (opens new window) 修改文件的权限
fchown() (opens new window) 改变文件的所有者
fstat() (opens new window) 由文件描述词取得文件状态
ftruncate() (opens new window) 改变文件大小
getcwd() (opens new window) 取得当前的工作目录
link() (opens new window) 建立文件连接
lstat() (opens new window) 由文件描述词取得文件状态
opendir() (opens new window) 打开目录函数
readdir() (opens new window) 读取目录函数
readlink() (opens new window) 取得符号连接所指的文件
rewinddir() (opens new window) 重设读取目录的位置为开头位置
seekdir() (opens new window) 设置下回读取目录的位置
stat() (opens new window) 获取文件状态
symlink() (opens new window) 建立文件符号连接
telldir() (opens new window) 取得目录流的读取位置
truncate() (opens new window) 改变文件大小
umask() (opens new window) 设置建立新文件时的权限遮罩
unlink() (opens new window) 删除文件
utime() (opens new window) 修改文件的存取时间和更改时间
utimes() (opens new window) 修改文件的存取时间和更改时间

# 9. 信号处理函数

函数 说明
alarm() (opens new window) 设置信号传送闹钟
kill() (opens new window) 传送信号给指定的进程
pause() (opens new window) 让进程暂停直到信号出现
sigaddset() (opens new window) 增加一个信号至信号集
sigdelset() (opens new window) 从信号集里删除一个信号
sigemptyset() (opens new window) 初始化信号集
sigfillset() (opens new window) 将所有信号加入至信号集
sigismember() (opens new window) 测试某个信号是否已加入至信号
signal() (opens new window) 设置信号处理方式
sigpending() (opens new window) 查询被搁置的信号
sigprocmask() (opens new window) 查询或设置信号遮罩
sleep() (opens new window) 让进程暂停执行一段时间
ferror() (opens new window) 检查文件流是否有错误发生
strerror() (opens new window) 返回错误原因的描述字符串
mkfifo() (opens new window) 建立具名管道
pclose() (opens new window) 关闭管道I/O
popen() (opens new window) 建立管道I/O
sigaction() (opens new window) 查询或设置信号处理方式

# 10. 接口处理函数

函数 说明
accept() (opens new window) 接受socket连线
bind() (opens new window) 对socket定位
connect() (opens new window) 建立socket连线
endprotoent() (opens new window) 结束网络协议数据的读取
endservent() (opens new window) 结束网络服务数据的读取
getsockopt() (opens new window) 取得socket 状态
htonl() (opens new window) 将32位主机字符顺序转换成网络字符顺序
htons() (opens new window) 将16位主机字符顺序转换成网络字符顺序
inet_addr() (opens new window) 将网络地址转成二进制的数字
inet_aton() (opens new window) 将网络地址转成网络二进制的数字
inet_ntoa() (opens new window) 将网络二进制的数字转换成网络地址
listen() (opens new window) 等待连接
ntohl() (opens new window) 将32位网络字符顺序转换成主机字符顺序
ntohs() (opens new window) 将16位网络字符顺序转换成主机字符顺序
recv() (opens new window) 经socket接收数据
recvfrom() (opens new window) 经socket接收数据
recvmsg() (opens new window) 经socket接收数据
send() (opens new window) 经socket传送数据
sendmsg() (opens new window) 经socket传送数据
sendto() (opens new window) 经socket传送数据
setprotoent() (opens new window) 打开网络协议的数据文件
setsockopt() (opens new window) 设置socket状态
shutdown() (opens new window) 终止socket通信
socket() (opens new window) 建立一个socket通信
setservent() (opens new window) 打开主机网络服务的数据文件

# 11. 环境变量函数

函数 说明
getenv() (opens new window) 取得环境变量内容
putenv() (opens new window) 改变或增加环境变量

# 12. 终端控制函数

函数 说明
getopt() (opens new window) 分析命令行参数
isatty() (opens new window) 判断文件描述词是否是为终端机
select() (opens new window) I/O多工机制
ttyname() (opens new window) 返回一终端机名称