博文

函数大全(n ,o开头)(2006-11-27 19:58:00)

摘要:
  void normvideo(void );
选择正常亮度字符。
将文本属性(前景和背景)置为启动程序时它所具有的值,来选择标准字符。 void nosound(void );
关闭由调用 sound而发声的扬声器。
函数名: open
功 能: 打开一个文件用于读或写
用 法: int open(char *pathname, int access[, int permiss]);
程序例: #include
#include
#include
#include int main(void)
{
int handle;
char msg[] = "Hello world"; if ((handle = open("TEST.$$$", O_CREAT | O_TEXT)) == -1)
{
perror("Error:");
return 1;
}
write(handle, msg, strlen(msg));
close(handle);
return 0;
}

函数名: outport
功 能: 输出整数到硬件端口中
用 法: void outport(int port, int value);
程序例: #include
#include
int main(void)
{
int value = 64;
int port = 0; outportb(port, value);
printf("Value %d sent to port number %d\n", value, port);
return 0;
}

函数名: outportb
功 能: 输出字节到硬件端口中
用 法: void outportb(int port, char byte);
程序例: #include
#include int main(void)
{
int value = 6......

阅读全文(1275) | 评论:0

函数大全(m开头)(2006-11-27 19:57:00)

摘要:
  main()主函数
每一C 程序都 必须 有一main()函数, 可以根据自己的爱好把它放在程序的某
个地方。有些程序员把它放在最前面, 而另一些程序员把它放在最后面, 无论放
在哪个地方, 以下几点说明都是适合的。
1. main() 参数
在Turbo C2.0启动过程中, 传递main()函数三个参数: argc, argv和env。
* argc: 整数, 为传给main()的命令行参数个数。
* argv: 字符串数组。
在DOS 3.X 版本中, argv[0] 为程序运行的全路径名; 对DOS 3.0
以下的版本, argv[0]为空串("") 。
argv[1] 为在DOS命令行中执行程序名后的第一个字符串;
argv[2] 为执行程序名后的第二个字符串;
...
argv[argc]为NULL。
*env: 安符串数组。env[] 的每一个元素都包含ENVVAR=value形式的字符
串。其中ENVVAR为环境变量如PATH或87。value 为ENVVAR的对应值如C:\DOS, C:
\TURBOC(对于PATH) 或YES(对于87)。
Turbo C2.0启动时总是把这三个参数传递给main()函数, 可以在用户程序中
说明(或不说明)它们, 如果说明了部分(或全部)参数, 它们就成为main()子程序
的局部变量。
请注意: 一旦想说明这些参数, 则必须按argc, argv, env 的顺序, 如以下
的例子:
main()
main(int argc)
main(int argc, char *argv[])
main(int argc, char *argv[], char *env[])
其中第二种情况是合法的, 但不常见, 因为在程序中很少有只用argc, 而不
用argv[]的情况。
以下提供一样例程序EXAMPLE.EXE, 演示如何在main()函数中使用三个参数:
/*program name EXAMPLE.EXE*/
#include
#inc......

阅读全文(1018) | 评论:0

函数大全(l开头)(2006-11-27 19:56:00)

摘要:
 
  函数名: labs
用 法: long labs(long n);
程序例: #include
#include int main(void)
{
long result;
long x = -12345678L; result= labs(x);
printf("number: %ld abs value: %ld\n",
x, result); return 0;
}


函数名: ldexp
功 能: 计算value*2的幂
用 法: double ldexp(double value, int exp);
程序例: #include
#include int main(void)
{
double value;
double x = 2; /* ldexp raises 2 by a power of 3
then multiplies the result by 2 */
value = ldexp(x,3);
printf("The ldexp value is: %lf\n",
value); return 0;
}

函数名: ldiv
功 能: 两个长整型数相除, 返回商和余数
用 法: ldiv_t ldiv(long lnumer, long ldenom);
程序例: /* ldiv example */ #include
#include int main(void)
{
ldiv_t lx; lx = ldiv(100000L, 30000L);
printf("100000 div 30000 = %ld remainder %ld\n", lx.quot, lx.rem);
return 0;
}
函数名: lfind
功 能: 执行线性搜索
用 法: void *lfind(void *key, void *base, int......

阅读全文(1431) | 评论:0

函数大全(k开头)(2006-11-27 19:54:00)

摘要:
  函数名: kbhit
功 能: 检查当前按下的键
用 法: int kbhit(void);
程序例: #include int main(void)
{
cprintf("Press any key to continue:");
while (!kbhit()) /* do nothing */ ;
cprintf("\r\nA key was pressed...\r\n");
return 0;
}
函数名: keep
功 能: 退出并继续驻留
用 法: void keep(int status, int size);
程序例: /***NOTE:
This is an interrupt service routine. You
can NOT compile this program with Test
Stack Overflow turned on and get an
executable file which will operate
correctly. Due to the nature of this
function the formula used to compute
the number of paragraphs may not
necessarily work in all cases. Use with
care! Terminate Stay Resident (TSR)
programs are complex and no other support
for them is provided. Refer to the
MS-DOS technical documentation
for more information. */
#include
/* The clock tick interrupt */
#define INTR 0x1C
/* Screen attribute (blue on grey) */
#defin......

阅读全文(1300) | 评论:0

函数大全(i开头)(2006-11-27 19:51:00)

摘要:
  函数名: imagesize
功 能: 返回保存位图像所需的字节数
用 法: unsigned far imagesize(int left, int top, int right, int bottom);
程序例: #include
#include
#include
#include #define ARROW_SIZE 10 void draw_arrow(int x, int y); int main(void)
{
/* request autodetection */
int gdriver = DETECT, gmode, errorcode;
void *arrow;
int x, y, maxx;
unsigned int size; /* initialize graphics and local variables */
initgraph(&gdriver, &gmode, ""); /* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
} maxx = getmaxx();
x = 0;
y = getmaxy() / 2; /* draw the image to be grabbed */
draw_arrow(x, y); /* calculate the size of the image */
size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y......

阅读全文(1982) | 评论:0

函数大全(h开头)(2006-11-27 19:50:00)

摘要:
  函数名: harderr
功 能: 建立一个硬件错误处理程序
用 法: void harderr(int (*fptr)());
程序例:
/*This program will trap disk errors and prompt
the user for action. Try running it with no
disk in drive A: to invoke its functions.*/ #include
#include
#include
#define IGNORE 0
#define RETRY 1
#define ABORT 2
int buf[500];
/*define the error messages for trapping disk problems*/
static char *err_msg[] = {
"write protect",
"unknown unit",
"drive not ready",
"unknown command",
"data error (CRC)",
"bad request",
"seek error",
"unknown media type",
"sector not found",
"printer out of paper",
"write fault",
"read fault",
"general failure",
"reserved",
"reserved",
"invalid disk change"
}; error_win(char *msg)
{
int retval; cputs(msg); /*prompt for user to press a key to abort, retry, ignore*/
while(1)
{
retval= getch();
if (retval == 'a' || retval == ......

阅读全文(1128) | 评论:0

函数大全(g开头)(2006-11-27 19:49:00)

摘要:  函数名: gcvt
功 能: 把浮点数转换成字符串
用 法: char *gcvt(double value, int ndigit, char *buf);
程序例: #include
#include int main(void)
{
char str[25];
double num;
int sig = 5; /* significant digits */ /* a regular number */
num = 9.876;
gcvt(num, sig, str);
printf("string = %s\n", str); /* a negative number */
num = -123.4567;
gcvt(num, sig, str);
printf("string = %s\n", str); /* scientific notation */
num = 0.678e5;
gcvt(num, sig, str);
printf("string = %s\n", str); return(0);
}


函数名: geninterrupt
功 能: 产生一个软中断
用 法: void geninterrupt(int intr_num);
程序例: #include
#include /* function prototype */
void writechar(char ch); int main(void)
{
clrscr();
gotoxy(80,25);
writechar('*');
getch();
return 0;
} /*
outputs a character at the current cursor
position using the video BIOS to avoid the
scrolling of the screen when writing to
l......

阅读全文(1381) | 评论:0

函数大全(f开头)(2006-11-27 19:47:00)

摘要:
  double fabs(double x); 返回双精度x的绝对值。
void far *farcalloc(unsigned long nunits,unsigned long unitsz); 堆中给含有nu从远nits个元素的,每个元素占用unitsz个字节长的数组分配存贮区。
成功是返回指向新分配的内存块的指针;若存贮空间不够,返回NULL。   unsigned long farcoreleft(void); 返回远堆中未用存贮区的大小。
void farfree(void far *block); 释放远堆中以前所分配内存块。
void far *farmalloc(unsigned long nbytes); 从远堆分配长nbytes字节的内存块,返回新地址。
void far *farrealloc(void far *oldblock,unsigned long nbytes); 调整已分配的内存块的大小为nbytes。需要的话,可把块中的内容复制到新位置。要注意:所有的可用的RAM可被分配,大于64K的块可被分配。
远指针用于存取被分配的块。返回重新分配的内存块的地址。若存贮块重新分配失败,返回NULL。 struct fcb { char fcb_drive; /* 0 = default, 1 = A, 2 = B */ char fcb_name[8]; /* File name */ char fcb_ext[3]; /* File extension */ short fcb_curblk; /* Current block number */ short fcb_recsize; /* Logical record size in bytes */ long fcb_filsize; /* File size in bytes */ short fcb_date; /* Date file was last written */ char fcb_resv[10]; /* Reserved for DOS */ char fcb_currec; /* Current record in bl......

阅读全文(1875) | 评论:0

函数大全(e开头)(2006-11-27 19:46:00)

摘要:
  函数名: ecvt
功 能: 把一个浮点数转换为字符串
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
程序例: #include
#include
#include int main(void)
{
char *string;
double value;
int dec, sign;
int ndig = 10; clrscr();
value = 9.876;
string = ecvt(value, ndig, &dec, &sign);
printf("string = %s dec = %d \
sign = %d\n", string, dec, sign); value = -123.45;
ndig= 15;
string = ecvt(value,ndig,&dec,&sign);
printf("string = %s dec = %d sign = %d\n",
string, dec, sign);
value = 0.6789e5; /* scientific
notation */
ndig = 5;
string = ecvt(value,ndig,&dec,&sign);
printf("string = %s dec = %d\
sign = %d\n", string, dec, sign); return 0;
}

函数名: ellipse
功 能: 画一椭圆
用 法: void far ellipse(int x, int y, int stangle, int endangle,
int xradius, int yradius);
程序例: #include
#include
#include
#include int main(void)
{
......

阅读全文(1131) | 评论:0

函数大全(d开头)(2006-11-27 19:44:00)

摘要:
  函数名: delay
功 能: 将程序的执行暂停一段时间(毫秒)
用 法: void delay(unsigned milliseconds);
程序例:
/* Emits a 440-Hz tone for 500 milliseconds */
#include int main(void)
{
sound(440);
delay(500);
nosound(); return 0;
}

函数名: delline
功 能: 在文本窗口中删去一行
用 法: void delline(void);
程序例: #include int main(void)
{
clrscr();
cprintf("The function DELLINE deletes \
the line containing the\r\n");
cprintf("cursor and moves all lines \
below it one line up.\r\n");
cprintf("DELLINE operates within the \
currently active text\r\n");
cprintf("window. Press any key to \
continue . . .");
gotoxy(1,2); /* Move the cursor to the
second line and first column */
getch(); delline();
getch(); return 0;
}
函数名: detectgraph
功 能: 通过检测硬件确定图形驱动程序和模式
用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
程序例: #include
#include
#include
#include /......

阅读全文(1300) | 评论:0