开奖网源码出租与标准库函数

非本地跳转”setjmp.h”
setjmp和longjmp函数提供类似goto语言的机制 开奖网源码出租企俄:2152876294 网址diguaym.com
int setjmp(jmp_buf state);
返回值:若直接调用则返回0,若从longjmp调用返回则返回非0值
void longjmp(jump_buf state,int value);

include “setjmp.h>
include”stdio.h>
jmp_buf jmpbuffer;
void main()
{
int a= setjmp(jmpbuffer);
int i;
int j;
while (a == 0)
{
for (i = 0; i <= 9; i++)
{
for (j = 0; j <= 9; j++)
{
printf(“%d,%d\n”, i, j);
if (i == 2 && j == 5)
{
longjmp(jmpbuffer, 1);
}
}
}
}
}
而直接用a=0改没用;

信号
信号名”signal.h”
SIGABRT 程序请求异常终止
SIGFPE 发生一个算术错误
SIGILL 检测到非法指令
SIGSEGV 检测到对内存的非法访问
SIGINT 收到一个交互性注意信号
SIGTERM 收到一个终止程序的请求

处理信号”signal.h”
int raise(int sig); 显示引发一个信号

volatile数据:防止编译器以一种可能修改程序含义的方式”优化”程序。比如
if (value)
{
a++;
}
else
{
a–;
}

if (value)
{
a++;
}
else
{
a–;
}
可能被优化为
if (value)
{
a+=2;
}
else
{
a-=2;
}

执行环境
终止执行”stdlib.h”
void abort(void);
用于不正常的终止一个正在执行的程序
void atexit(void(func )(void) );
可以把一些函数注册为退出函数。当程序将要正常终止时(exit,或者main返回),退出函数将被调用
void exit(int status);正常终止程序

include”stdio.h>
include”stdlib.h>
void func1()
{
printf(“The process is done…\n”);
}
void func2()
{
printf(“Clean up the processing\n”);
}
void func3()
{
printf(“Exit sucessful..\n”);
}
int main()
{
atexit(func1);
atexit(func2);
atexit(func3);
exit(0);
}
输出:
Exit sucessful..
Clean up the processing
The process is done…
Press any key to continue …

执行系统命令”stdlib.h”
void system(char const *command);把字符串参数传递给宿主操作系统,作为命令执行。

排序和查找”stdlib.h”
void qsort(void base,size_t n_elements,size_t el_size,int (compare)(void const,void const))快速排序;
数组,数目,长度,函数指针

char,整型:return (int )a - (int )b;小到大(b-a大到小)
double: return (double )a > (double )b ? 1 : -1;
一级结构体:return ((In )a).data > ((In )b).data ? 1 : -1;
字符串:return strcmp( ((In )a)->str , ((In )b)->str );

bsearch:在一个已经排好序的数组中用二分法查找一个特定的元素。返回一个指向查找到的数组元素的指针,不存在则返回NULL。
void bsearch(void constkey,void const base,isze_tn_elements,size_t el_size,int (compare)(void const ,void const ));
查找值的指针,数组,元素数目,长度,比较指针

int r_compare(void consta, void constb)
{
return (int )a - (int )b;
}
void main()
{
int a[10]={1,25, 3, 17,85,4, 5, 6, 78, 9};
qsort(a, 10, sizeof(a[0]),r_compare);
for (int i = 0; i <= 9; i++)
{
printf(“%d\n”,a[i]);
}
int i = 3;
int p = &i;
int
p1;
p1=(int )bsearch(p, a, 10, sizeof(a[0]),r_compare);
printf(“%d”,
p1);
}
输出:
1
3
4
5
6
9
17
25
78
85
3Press any key to continue …

猜你喜欢

转载自blog.51cto.com/13921155/2159036
今日推荐