📄 王大刚--c语言编程宝典--i.htm
字号:
<P> /* read result of last graphics operation */
<BR> errorcode = graphresult(); <BR> if (errorcode
!= grOk) <BR> { <BR>
printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); <BR> } <BR>} <BR>
<P>函数名: installuserfont <BR>功 能: 安装未嵌入BGI系统的字体文件(CHR) <BR>用 法:
int far installuserfont(char far *name); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>/* function prototype */ <BR>void checkerrors(void); <BR>
<P>int main(void) <BR>{ <BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode; <BR> int
userfont; <BR> int midx, midy; <BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, ""); <BR>
<P> midx = getmaxx() / 2; <BR> midy = getmaxy() /
2; <BR>
<P> /* check for any initialization errors */ <BR>
checkerrors(); <BR>
<P> /* install a user defined font file */ <BR>
userfont = installuserfont("USER.CHR"); <BR>
<P> /* check for any installation errors */ <BR>
checkerrors(); <BR>
<P> /* select the user font */ <BR>
settextstyle(userfont, HORIZ_DIR, 4); <BR>
<P> /* output some text */ <BR> outtextxy(midx,
midy, "Testing!"); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR>
<P>/* check for and report any graphics errors */ <BR>void
checkerrors(void) <BR>{ <BR> int errorcode; <BR>
<P> /* read result of last graphics operation */
<BR> errorcode = graphresult(); <BR> if (errorcode
!= grOk) <BR> { <BR>
printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); <BR> } <BR> }
<BR> <BR> <BR> <BR>
<P>函数名: int86 <BR>功 能: 通用8086软中断接口 <BR>用 法: int int86(int
intr_num, union REGS *inregs, union REGS *outregs); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <conio.h> <BR>#include
<dos.h> <BR>
<P>#define VIDEO 0x10 <BR>
<P>void movetoxy(int x, int y) <BR>{ <BR> union REGS regs;
<BR>
<P> regs.h.ah = 2; /* set cursor postion */
<BR> regs.h.dh = y; <BR> regs.h.dl = x;
<BR> regs.h.bh = 0; /* video page 0 */ <BR>
int86(VIDEO, &regs, &regs); <BR>} <BR>
<P>int main(void) <BR>{ <BR> clrscr(); <BR>
movetoxy(35, 10); <BR> printf("Hello\n"); <BR>
return 0; <BR>} <BR> <BR> <BR>
<P>函数名: int86x <BR>功 能: 通用8086软中断接口 <BR>用 法: int int86x(int
intr_num, union REGS *insegs, union REGS *outregs,
<BR> struct SREGS *segregs); <BR>程序例: <BR>
<P>#include <dos.h> <BR>#include <process.h> <BR>#include
<stdio.h> <BR>
<P>int main(void) <BR>{ <BR> char filename[80];
<BR> union REGS inregs, outregs; <BR> struct SREGS
segregs; <BR>
<P> printf("Enter filename: "); <BR>
gets(filename); <BR> inregs.h.ah = 0x43; <BR>
inregs.h.al = 0x21; <BR> inregs.x.dx = FP_OFF(filename);
<BR> segregs.ds = FP_SEG(filename); <BR>
int86x(0x21, &inregs, &outregs, &segregs); <BR>
printf("File attribute: %X\n", outregs.x.cx); <BR> return 0;
<BR>} <BR> <BR> <BR> <BR>
<P>函数名: intdos <BR>功 能: 通用DOS接口 <BR>用 法: int intdos(union REGS
*inregs, union REGS *outregs); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <dos.h> <BR>
<P>/* deletes file name; returns 0 on success, nonzero on failure */
<BR>int delete_file(char near *filename) <BR>{ <BR> union REGS
regs; <BR> int ret; <BR> regs.h.ah =
0x41;
/* delete file */ <BR> regs.x.dx = (unsigned) filename;
<BR> ret = intdos(&regs, &regs); <BR>
<P> /* if carry flag is set, there was an error */
<BR> return(regs.x.cflag ? ret : 0); <BR>} <BR>
<P>int main(void) <BR>{ <BR> int err; <BR> err =
delete_file("NOTEXIST.$$$"); <BR> if (!err)
<BR> printf("Able to delete
NOTEXIST.$$$\n"); <BR> else <BR>
printf("Not Able to delete NOTEXIST.$$$\n"); <BR> return 0;
<BR>} <BR> <BR> <BR> <BR>
<P>函数名: intdosx <BR>功 能: 通用DOS中断接口 <BR>用 法: int intdosx(union
REGS *inregs, union REGS *outregs, <BR>
struct SREGS *segregs); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <dos.h> <BR>
<P>/* deletes file name; returns 0 on success, nonzero on failure */
<BR>int delete_file(char far *filename) <BR>{ <BR> union REGS
regs; struct SREGS sregs; <BR> int ret; <BR>
regs.h.ah =
0x41;
/* delete file */ <BR> regs.x.dx = FP_OFF(filename);
<BR> sregs.ds = FP_SEG(filename); <BR> ret =
intdosx(&regs, &regs, &sregs); <BR>
<P> /* if carry flag is set, there was an error */
<BR> return(regs.x.cflag ? ret : 0); <BR>} <BR>
<P>int main(void) <BR>{ <BR> int err; <BR> err =
delete_file("NOTEXIST.$$$"); <BR> if (!err)
<BR> printf("Able to delete
NOTEXIST.$$$\n"); <BR> else <BR>
printf("Not Able to delete NOTEXIST.$$$\n"); <BR> return 0;
<BR>} <BR> <BR> <BR>
<P>函数名: intr <BR>功 能: 改变软中断接口 <BR>用 法: void intr(int intr_num,
struct REGPACK *preg); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <string.h> <BR>#include
<dir.h> <BR>#include <dos.h> <BR>
<P>#define CF 1 /* Carry flag */ <BR>
<P>int main(void) <BR>{ <BR> char directory[80];
<BR> struct REGPACK reg; <BR>
<P> printf("Enter directory to change to: "); <BR>
gets(directory); <BR> reg.r_ax = 0x3B <<
8; /* shift 3Bh into
AH */ <BR> reg.r_dx = FP_OFF(directory); <BR>
reg.r_ds = FP_SEG(directory); <BR> intr(0x21, &reg);
<BR> if (reg.r_flags & CF)
<BR> printf("Directory change failed\n");
<BR> getcwd(directory, 80); <BR> printf("The
current directory is: %s\n", directory); <BR> return 0; <BR>}
<BR> <BR> <BR>
<P>函数名: ioctl <BR>功 能: 控制I/O设备 <BR>用 法: int ioctl(int handle,
int cmd[,int *argdx, int argcx]); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <dir.h> <BR>#include
<io.h> <BR>
<P>int main(void) <BR>{ <BR> int stat; <BR>
<P> /* use func 8 to determine if the default drive is
removable */ <BR> stat = ioctl(0, 8, 0, 0); <BR>
if (!stat) <BR> printf("Drive %c is
removable.\n", getdisk() + 'A'); <BR> else
<BR> printf("Drive %c is not removable.\n",
getdisk() + 'A'); <BR> return 0; <BR>} <BR> <BR>
<BR> <BR>
<P>函数名: isatty <BR>功 能: 检查设备类型 <BR>用 法: int isatty(int
handle); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <io.h> <BR>
<P>int main(void) <BR>{ <BR> int handle; <BR>
<P> handle = fileno(stdprn); <BR> if
(isatty(handle)) <BR> printf("Handle %d is a
device type\n", handle); <BR> else
<BR> printf("Handle %d isn't a device
type\n", handle); <BR> return 0; <BR>} <BR> <BR>
<BR> <BR>
<P>函数名: itoa <BR>功 能: 把一整数转换为字符串 <BR>用 法: char *itoa(int
value, char *string, int radix); <BR>程序例: <BR>
<P>#include <stdlib.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> int number = 12345;
<BR> char string[25]; <BR>
<P> itoa(number, string, 10); <BR> printf("integer
= %d string = %s\n", number, string); <BR> return 0; <BR>}
<BR> <BR>
<HR width="94%" color=#ee9b73 SIZE=1>
</TD>
<TD class=tt3 vAlign=bottom width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/029.htm">后一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/027.htm">前一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/index.html">回目录</A><BR><A
href="http://www.hjflying.8u8.com/index.htm">回首页</A><BR></STRONG></TD></TR></TBODY></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -