当前位置: 首页 > 图文教程 > 开发语言 > C/C++ > C/C++:小编谈C语言函数那些事(39)
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. MK_FP函数
MK_FP函数的功能是设置一个远指针,其用法为:void far *MK_FP(unsigned seg, unsigned off);程序实例如下:
#include <dos.h>
#include <graphics.h>
int main(void)
{
int gd, gm, i;
unsigned int far *screen;
detectgraph(&gd, &gm);
if (gd == HERCMONO)
screen = MK_FP(0xB000, 0);
else
screen = MK_FP(0xB800, 0);
for (i=0; i<26; i++)
screen[i] = 0x0700 + ('a' + i);
return 0;
}
2. modf函数
modf函数的功能是把数分为指数和尾数,其用法为double modf(double value, double *iptr);程序实例代码如下:
#include <math.h>
#include <stdio.h>
int main(void)
{
double fraction, integer;
double number = 100000.567;
fraction = modf(number, &integer);
printf("The whole and fractional parts of %lf are %lf and %lf\n",
number, integer, fraction);
return 0;
}
3. movedata函数
movedata函数的功能是拷贝字节, 其用法为:void movedata(int segsrc, int offsrc, int segdest,
int offdest, unsigned numbytes);程序实例代码如下:
#include <mem.h>
#define MONO_BASE 0xB000
void save_mono_screen(char near *buffer)
{
movedata(MONO_BASE, 0, _DS, (unsigned)buffer, 80*25*2);
}
int main(void)
{
char buf[80*25*2];
save_mono_screen(buf);
}
4. movetext函数
movetext函数的功能是将屏幕文本从一个矩形区域拷贝到另一个矩形区域,其用法为:int movetext(int left, int top, int right, int bottom,int newleft, int newtop);程序实例代码如下:
#include <conio.h>
#include <string.h>
int main(void)
{
char *str = "This is a test string";
clrscr();
cputs(str);
getch();
movetext(1, 1, strlen(str), 2, 10, 10);
getch();
return 0;
}
评论 (0) All