C/C++——小编谈C语言函数那些事(11)
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. kbhit函数
kbhit函数是检查当前按下的键,其用法为:int kbhit(void);程序例子如下:
#include <conio.h>
int main(void)
{
cprintf("Press any key to continue:");
while (!kbhit()) /* do nothing */ ;
cprintf("\r\nA key was pressed...\r\n");
return 0;
}
2. keep函数
keep函数是退出并继续驻留,其用法为:void keep(int status, int size);程序例子如下:
#include <dos.h>
#define INTR 0x1C
#define ATTR 0x7900
extern unsigned _heaplen = 1024;
extern unsigned _stklen = 512;
void interrupt ( *oldhandler)(void);
void interrupt handler(void)
{
unsigned int (far *screen)[80];
static int count;
screen = MK_FP(0xB800,0);
count++;
count %= 10;
screen[0][79] = count + '0' + ATTR;
oldhandler();
}
int main(void)
{
oldhandler = getvect(INTR);
setvect(INTR, handler);
keep(0, (_SS + (_SP/16) - _psp));
return 0;
}
3. lfind函数
Lfind函数是执行线性搜索,其用法为:void *lfind(void *key, void *base, int *nelem, int width, int (*fcmp)()); 程序例子如下:
#include <stdio.h>
#include <stdlib.h>
int compare(int *x, int *y)
{
return( *x - *y );
}
int main(void)
{
int array[5] = {35, 87, 46, 99, 12};
size_t nelem = 5;
int key;
int *result;
key = 99;
result = lfind(&key, array, &nelem,
sizeof(int), (int(*)(const void *,const void *))compare);
if (result)
printf("Number %d found\n",key);
else
printf("Number %d not found\n",key);
return 0;
}
相关文档:
curl c api
关于Curl的介绍很多,这里不详细介绍,主要谈一下简单应用。
最近研究了一下Linux下的curl C API,curl c API的文档比较丰富,唯一就是查找起来,费些时间。Curl的C API和curl的PHP API,函数接口和作用大致相同,所以如果有PHP API使用经验应该很好理解。
1:CURLcode curl_global_init(long flags);函 ......
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. fgetc函数
fgetc函数的功能是从流中读取字符,其用法是:int fgetc(FILE *stream); 程序例子如下:
#include <string.h ......
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. gcvt函数
gcvt函数的功能是把浮点数转换成字符串,其用法是:char *gcvt(double value, int ndigit, char *buf);程序 ......
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. harderr函数
harderr函数的功能是建立一个硬件错误处理程序,其用法是:void harderr(int (*fptr)());程序例子如下:
#include <stdio.h>
......