ACM c函数大全
函数名: abs 功 能: 求整数的绝对值
用 法: int abs(int i);
程序例:
#include <stdio.h>
#include <math.h>
int main(void)
{
int number = -1234;
printf("number: %d absolute value: %d\n", number, abs(number));
return 0;
}
函数名: atof
功 能: 把字符串转换成浮点数
用 法: double atof(const char *nptr);
程序例:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
float f;
char *str = "12345.67";
f = atof(str);
printf("string = %s float = %f\n", str, f);
return 0;
}
函数名: atoi
功 能: 把字符串转换成长整型数
用 法: int atoi(const char *nptr);
程序例:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int n;
char *str = "12345.67";
n = atoi(str);
printf("string = %s integer = %d\n", str, n);
return 0;
}
函数名: atol
功 能: 把字符串转换成长整型数
用 法: long atol(const char *nptr);
程序例:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
long l;
char *str = "98765432";
l = atol(lstr);
printf("string = %s integer = %ld\n", str, l);
return(0);
}
函数名: bsearch
功 能: 二分法搜索
用 法: void *bsearch(const void *key, const void *base, size_t *nelem, size_t width, int(*fcmp)(const void *, const *));
程序例:
#include <stdlib.h>
#include <stdio.h>
#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0]))
int numarray[] = {123, 145, 512, 627, 800, 933};
int numeric (const int *p1, const int *p2)
{
return(*p1 - *p2);
}
int lookup(int key)
{
int *itemptr;
/* The cast of (int(*)(const void *,const void*))
is needed to avoid a type mismatch error at
compile time */
&
相关文档:
1.求下面函数的返回值(微软)
int func(x)
{
int countx = 0;
while(x)
{
countx
++;
x = x&(x-1);
}
return countx;
}
假定x = 9999。 答案:8
思路:将x转化为2进制,看含有的1的个数。
2. 什么是“引用”?申明和使用“引用”要注意哪些问题?
答:引用就是某个目标变量的&l ......
一. 概述
内存泄漏一直是软件开发人员最头大的问题之一,尤其像C/C++这样自由度非常大的编程语言,几乎是每一个用其开发出来的软件都会出现内存泄漏的情况。
如果没有内存泄漏,世界或许会变的美好。然而,完全美好的世界是不存在的,我们能做的就是尽量让它变的更美 ......
C输出格式总结 收藏
C输出格式总结
1 一般格式
printf(格式控制,输出表列)
例如:printf("i=%d,ch=%c\n",i,ch);
说明:
(1)“格式控制”是用双撇号括起来的字符串,也称“转换控制字符串”,它包括两种信息:
&nbs ......
引言
最近笔者一直在做JPEG的解码工作,发现用完全使用哈夫曼树进行解码比较费时,而使用表结构存储编码和值的对应关系比较快捷,但是也存在比较难处理的地方,比如解码工作通常是以位为单位的操作,这里必然会涉及到移位操作,而笔者之前对位的操作很少,经验很欠缺,经过这次历练终于发现了一个自己曾经忽视的东西,那就 ......