C语言中一些不常用函数
2015-05-11 09:43
169 查看
time
这个用的最多就是随机数的时候,现在用一用其他特性.
字符转换/数学公式
把字符串转化成浮点数:double atof( const char *str );
或 double strtod( const char *start, char **end );
把字符串转化成整型数:int atoi( const char *str );
长整型:long atol( const char *str );
二分查找:
void bsearch(const void *key, const void *buf, size_t num, size_t size, int (*compare)(const void , const void *));
以十为底的对数函数:double log10(double x);
以e(=2.71828)为底:double log(double x);
反正切函数:double atan(double x); //返回值范围(-PI/2,PI/2)
double atan2(double y, double x); //返回点(x,y)与原点的连线和x轴正方向的夹角(弧度制),范围(-PI,PI]
说明: 1.特别注意:参数的顺序是y,x,不是x,y.
2.结果为正表示从x 轴逆时针旋转的角度,结果为负表示从x 轴顺时针旋转的角度.
3.atan2(y, x) 与 atan(y/x) 返回值的范围不同.
4.当x=0,y=0时返回错误.
这个用的最多就是随机数的时候,现在用一用其他特性.
#include <stdio.h> #include <time.h> int main() { time_t sec; ///typedef long time_t struct tm * curTime; sec = time(NULL); ///获取时间,从1970.1.1到现在的秒数,也可以写成 time(&sec); curTime = localtime(&sec); ///把sec转换为当地时间,存于时间结构体curTime中,注意返回值是struct tm* 类型的 printf("asctime(curTime): %s\n", asctime (curTime)); ///asctime(struct tm*)函数将curTime转化成标准ASCII时间格式 printf("ctime(curTime): %s\n", ctime (&sec)); ///ctime(time_t*)直接将sec转换成标准时间格式 printf("%d-%d-%d %d:%d:%d\n", 1900+curTime->tm_year, 1+curTime->tm_mon, curTime->tm_mday, curTime->tm_hour, curTime->tm_min, curTime->tm_sec); ///手动输出struct tm中的字段,其中月份加1,年份要加1900, ///sec记录的是1970到现在的秒数,为什么是加1900呢??? printf("\nsec = %ld\nmktime(curTime) = %ld\n", sec, mktime(curTime)); ///time_t mktime(struct tm*)将curTime反向转化成1970到现在的秒数 return 0; }
字符转换/数学公式
#include <stdlib.h>
把字符串转化成浮点数:double atof( const char *str );
或 double strtod( const char *start, char **end );
把字符串转化成整型数:int atoi( const char *str );
长整型:long atol( const char *str );
二分查找:
void bsearch(const void *key, const void *buf, size_t num, size_t size, int (*compare)(const void , const void *));
#include <math.h>
以十为底的对数函数:double log10(double x);
以e(=2.71828)为底:double log(double x);
反正切函数:double atan(double x); //返回值范围(-PI/2,PI/2)
double atan2(double y, double x); //返回点(x,y)与原点的连线和x轴正方向的夹角(弧度制),范围(-PI,PI]
说明: 1.特别注意:参数的顺序是y,x,不是x,y.
2.结果为正表示从x 轴逆时针旋转的角度,结果为负表示从x 轴顺时针旋转的角度.
3.atan2(y, x) 与 atan(y/x) 返回值的范围不同.
4.当x=0,y=0时返回错误.
相关文章推荐
- 关于C语言中一些常用函数的说明
- C语言中一些常用IO函数的总结
- 慢慢总结C语言一些常用函数
- C语言一些常用内存分配函数
- C语言的常用库函数(dos)之四(dir.h文件下的一些函数)
- C语言一些常用的“位”操作函数
- 关于C语言中一些常用函数的说明
- C语言一些常用的“位”操作函数
- C语言中关于字符串的一些常用函数
- C语言一些常用的“位”操作函数
- c语言中一些常用的函数
- 一些常用函数,as:strnstr,memchr。。。。。
- c语言中常用函数
- C语言的常用库函数使用方法分析及用途(13)
- 【编程 C】 对C语言编译初级算法的一些心得---函数(1)
- Tensorflow一些常用基本概念与函数
- Tensorflow一些常用基本概念与函数(一)
- 收集一些非常好用常用的用户函数。分享给大家参考。
- 格式整齐的linuxC语言常用函数
- 音频信号MATLAB处理的一些常用函数