linux中以A开头的函数使用方式历程及详解
A开头的Linux C
函数
abort
异常终止程序
abort
函数在调用的时候,会触发SIGABRT
信号
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>static void signalHandler(int sig);// 信号处理函数
void signalHandler(int sig)
{if(sig == SIGABRT) //对应ctrl+c{printf("abort 函数被调用,触发SIGABRT信号量 。\n");}
}
//以下是主函数
int main(int argc,char *argv[])
{signal(SIGABRT, signalHandler); //注册SIGINT对应的处理函数abort();printf("程序走不到这里。\n");return 0;
}
abs
对整数求绝对值的函数
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
/*┌──────────────────────────────┬───────────────┬─────────┐│Interface │ Attribute │ Value │├──────────────────────────────┼───────────────┼─────────┤│abs(), labs(), llabs(), imax‐ │ Thread safety │ MT-Safe ││abs() │ │ │└──────────────────────────────┴───────────────┴─────────┘
*/
int main(int argc, char const *argv[])
{/* code */printf("abs(-1) = [%d]\n", abs(-1));return 0;
}
acos
反余弦函数
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>/*┌─────────────────────────┬───────────────┬─────────┐│Interface │ Attribute │ Value │├─────────────────────────┼───────────────┼─────────┤│acos(), acosf(), acosl() │ Thread safety │ MT-Safe │└─────────────────────────┴───────────────┴─────────┘
*/int main(int argc, char const *argv[])
{double real = acos(-0.5);printf("%lf\n", real);return 0;
}
asctime time localtime
系统时间获取函数,注意这几个函数的时间受校时函数的影响
time() returns the time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC)
loacaltime() 将time_t 结构的数据,转换为对应的日历时间,详见tm结构体
asctime() 将日历形式结构体时间数据转换为对应的字符串
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include <time.h>
#include <string.h>#if 0
struct tm
{int tm_sec; /* Seconds. [0-60] (1 leap second) */int tm_min; /* Minutes. [0-59] */int tm_hour; /* Hours. [0-23] */int tm_mday; /* Day. [1-31] */int tm_mon; /* Month. [0-11] */int tm_year; /* Year - 1900. */int tm_wday; /* Day of week. [0-6] */int tm_yday; /* Days in year.[0-365] */int tm_isdst; /* DST. [-1/0/1]*/long int __tm_gmtoff; const char *__tm_zone;
};
#endifint main(int argc, char const *argv[])
{//定义时间结构体指针,结构体值见注释struct tm *pTm = NULL;time_t nowTime;char *pSzAscTime = NULL;memset(&nowTime, 0 , sizeof(nowTime));nowTime = time(NULL);pTm = localtime(&nowTime);pSzAscTime = asctime(pTm);printf("Asc time = %s", pSzAscTime);return 0;
}
asin
反正弦函数
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>int main(int argc, char const *argv[])
{double real = asin(-0.5);printf("%lf\n", real);return 0;
}
assert
assert()函数是诊断函数,诊断一个表达式是否为真,只有为真才能继续执行
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include <assert.h>/*** 诊断表达式的真值* */int main(int argc, char const *argv[])
{assert(1);return 0;
}
atan
atan() 反正弦函数
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>int main(int argc, char const *argv[])
{double real = atan(-0.5);printf("%lf\n", real);return 0;
}
atexit
atexit() 在程序要退出时注册要调用的函数
该函数在做项目,一个进程中有多个线程,又申请内存需要释放的时候,非常有用,将需要释放的内存放到被注册的函数里面,无论在那个线程里面退出程序,都会出发释放资源的函数,这样就不用担心资源的释放问题了。
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>// C语言中用于注册 正常退出时调用的函数
// 当程序调用exit函数进行推出时就会先调用atexit函数注册的函数
#define TRUE 1 //真
#define FALSE 0 //假
#define YES 1 //是
#define NO 0 //否
#define OK 0 //通过
#define ERROR -1 //错误void callHnadler(void);void callHnadler(void)
{printf("这个函数会在函数退出前调用一次\n");
}int main(int argc, char const *argv[])
{int ret = ERROR; ret = atexit(callHnadler);if(OK != ret){printf("atexit register callHandler function failed\n");}return 0;
}
atof
将字符串转换为浮点数的函数
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>// 将字符串转换为浮点数的函数int main(int argc, char const *argv[])
{printf("0.12345 = [%f]\n", atof("0.12345"));return 0;
}
atoi
将字符串转换为整数的函数
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>// 将字符串转化为整数的函数int main(int argc, char const *argv[])
{printf("12345 = [%d]\n", atoi("12345"));return 0;
}
atol
将字符串转换为长整型的函数
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>// 将字符串转化为整数的函数int main(int argc, char const *argv[])
{printf("12345 = [%d]\n", atol("12345"));return 0;
}
扫码关注,一起探究linux编程的乐趣
linux中以A开头的函数使用方式历程及详解相关推荐
- linux切换用户无法加载变量,Linux 中用户切换:su 和 su- 的使用 环境变量详解
大部分Linux发行版的默认帐户是普通用户,而更改系统文件或者执行某些命令,须要root身份才能进行,这就须要从当前用户切换到root用户,Linux中切换用户的命令是su或su -,下面就su命令和 ...
- Linux中通过mkdir –p 能够创建多级目录(mkdir -p详解)
<!--一个博主专栏付费入口结束--><link rel="stylesheet" href="https://csdnimg.cn/release/p ...
- linux中quota信息查看,quota命令_Linux quota命令使用详解:显示磁盘已使用的空间与限制...
quota命令用于显示用户或者工作组的磁盘配额信息.输出信息包括磁盘使用和配额限制. 语法 quota(选项)(参数) 选项 -g:列出群组的磁盘空间限制: -q:简明列表,只列出超过限制的部分: - ...
- linux中使用u盘和光驱的命令_linux命令详解之挂载光驱的方法
linux的硬件设备在/dev目录下,光驱也是其中. /dev/cdrom表示光驱,挂载光驱的方法如下(以root身份): mkdir /mnt/cdrom mount -t auto -o ro ...
- linux 按键驱动中断 rockchip_7.自己写中断方式按键驱动程序(详解)
request_irq()和free_irq()分析完毕后,接下来开始编写上升沿中断的按键驱动 如下图,需要设置4个按键的EINT0, EINT2, EINT11, EINT19的模式为双边沿,且设置 ...
- Linux服务端开发——Linux中stat函数和stat命令使用详解
这篇文章主要介绍了Linux中stat函数和stat命令使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧 stat函数和s ...
- Python中Print()函数的用法___实例详解(二)(全,例多)
Python中Print()函数的用法___实例详解(二)(全,例多) 目录 十一.Print()小例子 十二.Print()中文输入显示乱码问题 十三.Print()写入文件 十四.print()在 ...
- 19. linux中权限详解,Linux权限位,读写执行权限真正含义,chmod详解
linux中权限详解,Linux权限位,读写执行权限真正含义,chmod详解 文章目录 Linux权限位 读写执行 三种权限真正含义和作用 权限对文件的作用 权限对目录的作用 示例 chmod 使用数 ...
- 站长在线Python精讲:在Python中函数的定义与创建详解
欢迎你来到站长在线的站长学堂学习Python知识,本文学习的是<在Python中函数的定义与创建详解>.本文的主要内容有:函数的定义.函数的定义规则.函数的创建. 目录 1.函数的定义 2 ...
最新文章
- 利用gevent实现异步执行任务
- Activity和Task
- Python的IDE之PyCharm:PyCharm的简介、安装、入门、使用方法之详细攻略
- OO实现ALV TABLE 五:ALV的栏位属性
- 《玩转微信6.0》一1.2 微信初体验
- ubuntu安装cgroup-tools
- zuul 自定义策略_如何为您的社区定义指标策略
- 随想录(webbench压力测试代码)
- ubuntu安装atom
- 通过python爬取数据
- Atitit 大数据索引技术attilax总结 目录 1. 面临的问题	2 1.1. 找到太多数据	2 1.2. 不支持多字段搜索	2 1.3. 不支持模糊搜索	2 1.4. 聚合搜索	2 1.5
- 一文入门推荐系统——推荐系统实践读书笔记
- 记录:The field files exceeds its maximum permitted size of 1048576 bytes...解决方案【亲测有效】
- 怎么配置计算机的ip,怎么设置电脑IP地址
- Hadoop访问不了9870、8088
- 新人报道,请多多关照。
- Java核心技术 卷Ⅰ 基础知识(原书第10版)
- 7-41 计算阶乘和
- 【C Primer Plus】温度转换器
- n皇后 回溯法 c++