ACM总结——库函数(2)C标准库stdlib

    技术2022-07-20  69

    ACM总结   https://blog.csdn.net/nameofcsdn/article/details/107673040

     

    1,字符串转为整数

    1double atof(const char *str) 把参数 str 所指向的字符串转换为一个浮点数(类型为 double 型)。2int atoi(const char *str) 把参数 str 所指向的字符串转换为一个整数(类型为 int 型)。3long int atol(const char *str) 把参数 str 所指向的字符串转换为一个长整数(类型为 long int 型)。

    这里的转换只能是10进制的,其他进制的函数参考

    ACM模板(5)整数相关计算 https://blog.csdn.net/nameofcsdn/article/details/107084737

     

    2,二分查找bsearch

    void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *)) key -- 指向要查找的元素的指针,类型转换为 void*。base -- 指向进行查找的数组的第一个对象的指针,类型转换为 void*。nitems -- base 所指向的数组中元素的个数。size -- 数组中每个元素的大小,以字节为单位。compar -- 用来比较两个元素的函数。

    如果查找成功,该函数返回一个指向数组中匹配元素的指针,否则返回空指针。.

     

    3,排序qsort

    void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*)) base -- 指向要排序的数组的第一个元素的指针。nitems -- 由 base 指向的数组中元素的个数。size -- 数组中每个元素的大小,以字节为单位。compar -- 用来比较两个元素的函数。

     

    4,绝对值

    int abs(int x) long int labs(long int x)

    Processed: 0.008, SQL: 9