C/C++——小编谈C语言函数那些事(25)
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. setwritemode函数
setwritemode函数的功能是设置图形方式下画线的输出模式,其用法为:void far setwritemode(int mode);程序实例如下:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver = DETECT, gmode, errorcode;
int xmax, ymax;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
xmax = getmaxx();
ymax = getmaxy();
setwritemode(XOR_PUT);
line(0, 0, xmax, ymax);
getch();
line(0, 0, xmax, ymax);
getch();
setwritemode(COPY_PUT);
line(0, 0, xmax, ymax);
getch();
closegraph();
return 0;
}
2. signal函数
signal函数的功能是设置某一信号的对应动作,其用法为int signal(int sig, sigfun fname);程序实例代码如下:
#pragma inline
#include <stdio.h>
#include <signal.h>
void Catcher(int sig, int type, int *reglist)
{
printf("Caught it!\n");
*(reglist + 8) = 3;
}
int main(void)
{
signal(SIGFPE, Catcher);
asm mov ax,07FFFH
asm in
相关文档:
某些场合,如游戏开发,工程计算中,可能需要计算反三角函数,下面是计算反正切三角函数的c源代码实例:
atan_self(double x)
{
//atan(x)=x-x^3/3+x^5/5-x^7/7+.....(-1<x<1)
//return:[-pi/2,pi/2]
double mult,sum,xx;
sum=0;
if(x==1){
return pi/4;
}
if(x==-1){
return -pi/4;
}
((x&g ......
编译和连接程序
MySQL中有一个特殊的脚本,叫做mysql_config. 它会为你编译MySQL客户端,并连接到MySQL服务器提供有用的信息.你需要使用下面两个选项.
1. --libs 选项 - 连接MySQL客户端函数库所需要的库和选项.
$ mysql_config --libs
2. --cflags 选项 - 使用必要的include文件的选项等等.
......
题目:输入三个字符串a,b和c,将a中b的第一次出现替换为c。
代码:
#include <iostream.h>
#include <string.h>
/*字符串替换,第一个参数为原串,第二个参数为要匹配的子串
第三个参数为要替换的第一个子串中包含第二个子串的部分*/
char *strReplace(char *str1,char *str2,char *str3);
void main() ......
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. setmem函数
setmem函数的功能是存值到存储区,其用法为:void setmem(void *addr, int len, char value);程序实例如下:
#include <stdio.h& ......