⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 王大刚--c语言编程宝典--i.htm

📁 初学者的良师益友。其中包括C的全部教程。
💻 HTM
📖 第 1 页 / 共 2 页
字号:
      <P>&nbsp;&nbsp; /* read result of last graphics operation */ 
      <BR>&nbsp;&nbsp; errorcode = graphresult(); <BR>&nbsp;&nbsp; if (errorcode 
      != grOk) <BR>&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("Graphics error: %s\n", grapherrormsg(errorcode)); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; } <BR>} <BR>
      <P>函数名: installuserfont <BR>功&nbsp; 能: 安装未嵌入BGI系统的字体文件(CHR) <BR>用&nbsp; 法: 
      int far installuserfont(char far *name); <BR>程序例: <BR>
      <P>#include &lt;graphics.h&gt; <BR>#include &lt;stdlib.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>
      <P>/* function prototype */ <BR>void checkerrors(void); <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; /* request auto detection */ 
      <BR>&nbsp;&nbsp; int gdriver = DETECT, gmode; <BR>&nbsp;&nbsp; int 
      userfont; <BR>&nbsp;&nbsp; int midx, midy; <BR>
      <P>&nbsp;&nbsp; /* initialize graphics and local variables */ 
      <BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, ""); <BR>
      <P>&nbsp;&nbsp; midx = getmaxx() / 2; <BR>&nbsp;&nbsp; midy = getmaxy() / 
      2; <BR>
      <P>&nbsp;&nbsp; /* check for any initialization errors */ <BR>&nbsp;&nbsp; 
      checkerrors(); <BR>
      <P>&nbsp;&nbsp; /* install a user defined font file */ <BR>&nbsp;&nbsp; 
      userfont = installuserfont("USER.CHR"); <BR>
      <P>&nbsp;&nbsp; /* check for any installation errors */ <BR>&nbsp;&nbsp; 
      checkerrors(); <BR>
      <P>&nbsp;&nbsp; /* select the user font */ <BR>&nbsp;&nbsp; 
      settextstyle(userfont, HORIZ_DIR, 4); <BR>
      <P>&nbsp;&nbsp; /* output some text */ <BR>&nbsp;&nbsp; outtextxy(midx, 
      midy, "Testing!"); <BR>
      <P>&nbsp;&nbsp; /* clean up */ <BR>&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; 
      closegraph(); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>
      <P>/* check for and report any graphics errors */ <BR>void 
      checkerrors(void) <BR>{ <BR>&nbsp;&nbsp; int errorcode; <BR>
      <P>&nbsp;&nbsp; /* read result of last graphics operation */ 
      <BR>&nbsp;&nbsp; errorcode = graphresult(); <BR>&nbsp;&nbsp; if (errorcode 
      != grOk) <BR>&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("Graphics error: %s\n", grapherrormsg(errorcode)); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; } <BR>&nbsp;} 
      <BR>&nbsp; <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: int86 <BR>功&nbsp; 能: 通用8086软中断接口 <BR>用&nbsp; 法: int int86(int 
      intr_num, union REGS *inregs, union REGS *outregs); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>#include 
      &lt;dos.h&gt; <BR>
      <P>#define VIDEO 0x10 <BR>
      <P>void movetoxy(int x, int y) <BR>{ <BR>&nbsp;&nbsp; union REGS regs; 
<BR>
      <P>&nbsp;&nbsp; regs.h.ah = 2;&nbsp; /* set cursor postion */ 
      <BR>&nbsp;&nbsp; regs.h.dh = y; <BR>&nbsp;&nbsp; regs.h.dl = x; 
      <BR>&nbsp;&nbsp; regs.h.bh = 0;&nbsp; /* video page 0 */ <BR>&nbsp;&nbsp; 
      int86(VIDEO, &amp;regs, &amp;regs); <BR>} <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; clrscr(); <BR>&nbsp;&nbsp; 
      movetoxy(35, 10); <BR>&nbsp;&nbsp; printf("Hello\n"); <BR>&nbsp;&nbsp; 
      return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: int86x <BR>功&nbsp; 能: 通用8086软中断接口 <BR>用&nbsp; 法: int int86x(int 
      intr_num, union REGS *insegs, union REGS *outregs, 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp; struct SREGS *segregs); <BR>程序例: <BR>
      <P>#include &lt;dos.h&gt; <BR>#include &lt;process.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char filename[80]; 
      <BR>&nbsp;&nbsp; union REGS inregs, outregs; <BR>&nbsp;&nbsp; struct SREGS 
      segregs; <BR>
      <P>&nbsp;&nbsp; printf("Enter filename: "); <BR>&nbsp;&nbsp; 
      gets(filename); <BR>&nbsp;&nbsp; inregs.h.ah = 0x43; <BR>&nbsp;&nbsp; 
      inregs.h.al = 0x21; <BR>&nbsp;&nbsp; inregs.x.dx = FP_OFF(filename); 
      <BR>&nbsp;&nbsp; segregs.ds = FP_SEG(filename); <BR>&nbsp;&nbsp; 
      int86x(0x21, &amp;inregs, &amp;outregs, &amp;segregs); <BR>&nbsp;&nbsp; 
      printf("File attribute: %X\n", outregs.x.cx); <BR>&nbsp;&nbsp; return 0; 
      <BR>} <BR>&nbsp; <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: intdos <BR>功&nbsp; 能: 通用DOS接口 <BR>用&nbsp; 法: int intdos(union REGS 
      *inregs, union REGS *outregs); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;dos.h&gt; <BR>
      <P>/* deletes file name; returns 0 on success, nonzero on failure */ 
      <BR>int delete_file(char near *filename) <BR>{ <BR>&nbsp;&nbsp; union REGS 
      regs; <BR>&nbsp;&nbsp; int ret; <BR>&nbsp;&nbsp; regs.h.ah = 
      0x41;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      /* delete file */ <BR>&nbsp;&nbsp; regs.x.dx = (unsigned) filename; 
      <BR>&nbsp;&nbsp; ret = intdos(&amp;regs, &amp;regs); <BR>
      <P>&nbsp;&nbsp; /* if carry flag is set, there was an error */ 
      <BR>&nbsp;&nbsp; return(regs.x.cflag ? ret : 0); <BR>} <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; int err; <BR>&nbsp;&nbsp; err = 
      delete_file("NOTEXIST.$$$"); <BR>&nbsp;&nbsp; if (!err) 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Able to delete 
      NOTEXIST.$$$\n"); <BR>&nbsp;&nbsp; else <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("Not Able to delete NOTEXIST.$$$\n"); <BR>&nbsp;&nbsp; return 0; 
      <BR>} <BR>&nbsp; <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: intdosx <BR>功&nbsp; 能: 通用DOS中断接口 <BR>用&nbsp; 法: int intdosx(union 
      REGS *inregs, union REGS *outregs, <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      struct SREGS *segregs); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;dos.h&gt; <BR>
      <P>/* deletes file name; returns 0 on success, nonzero on failure */ 
      <BR>int delete_file(char far *filename) <BR>{ <BR>&nbsp;&nbsp; union REGS 
      regs; struct SREGS sregs; <BR>&nbsp;&nbsp; int ret; <BR>&nbsp;&nbsp; 
      regs.h.ah = 
      0x41;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      /* delete file */ <BR>&nbsp;&nbsp; regs.x.dx = FP_OFF(filename); 
      <BR>&nbsp;&nbsp; sregs.ds = FP_SEG(filename); <BR>&nbsp;&nbsp; ret = 
      intdosx(&amp;regs, &amp;regs, &amp;sregs); <BR>
      <P>&nbsp;&nbsp; /* if carry flag is set, there was an error */ 
      <BR>&nbsp;&nbsp; return(regs.x.cflag ? ret : 0); <BR>} <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; int err; <BR>&nbsp;&nbsp; err = 
      delete_file("NOTEXIST.$$$"); <BR>&nbsp;&nbsp; if (!err) 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Able to delete 
      NOTEXIST.$$$\n"); <BR>&nbsp;&nbsp; else <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("Not Able to delete NOTEXIST.$$$\n"); <BR>&nbsp;&nbsp; return 0; 
      <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: intr <BR>功&nbsp; 能: 改变软中断接口 <BR>用&nbsp; 法: void intr(int intr_num, 
      struct REGPACK *preg); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;string.h&gt; <BR>#include 
      &lt;dir.h&gt; <BR>#include &lt;dos.h&gt; <BR>
      <P>#define CF 1&nbsp; /* Carry flag */ <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char directory[80]; 
      <BR>&nbsp;&nbsp; struct REGPACK reg; <BR>
      <P>&nbsp;&nbsp; printf("Enter directory to change to: "); <BR>&nbsp;&nbsp; 
      gets(directory); <BR>&nbsp;&nbsp; reg.r_ax = 0x3B &lt;&lt; 
      8;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* shift 3Bh into&nbsp; 
      AH */ <BR>&nbsp;&nbsp; reg.r_dx = FP_OFF(directory); <BR>&nbsp;&nbsp; 
      reg.r_ds = FP_SEG(directory); <BR>&nbsp;&nbsp; intr(0x21, &amp;reg); 
      <BR>&nbsp;&nbsp; if (reg.r_flags &amp; CF) 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Directory change failed\n"); 
      <BR>&nbsp;&nbsp; getcwd(directory, 80); <BR>&nbsp;&nbsp; printf("The 
      current directory is: %s\n", directory); <BR>&nbsp;&nbsp; return 0; <BR>} 
      <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: ioctl <BR>功&nbsp; 能: 控制I/O设备 <BR>用&nbsp; 法: int ioctl(int handle, 
      int cmd[,int *argdx, int argcx]); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;dir.h&gt; <BR>#include 
      &lt;io.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; int stat; <BR>
      <P>&nbsp;&nbsp; /* use func 8 to determine if the default drive is 
      removable */ <BR>&nbsp;&nbsp; stat = ioctl(0, 8, 0, 0); <BR>&nbsp;&nbsp; 
      if (!stat) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Drive %c is 
      removable.\n", getdisk() + 'A'); <BR>&nbsp;&nbsp; else 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Drive %c is not removable.\n", 
      getdisk() + 'A'); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; 
      <BR>&nbsp; <BR>
      <P>函数名: isatty <BR>功&nbsp; 能: 检查设备类型 <BR>用&nbsp; 法: int isatty(int 
      handle); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;io.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; int handle; <BR>
      <P>&nbsp;&nbsp; handle = fileno(stdprn); <BR>&nbsp;&nbsp; if 
      (isatty(handle)) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Handle %d is a 
      device type\n", handle); <BR>&nbsp;&nbsp; else 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Handle %d isn't a device 
      type\n", handle); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; 
      <BR>&nbsp; <BR>
      <P>函数名: itoa <BR>功&nbsp; 能: 把一整数转换为字符串 <BR>用&nbsp; 法: char *itoa(int 
      value, char *string, int radix); <BR>程序例: <BR>
      <P>#include &lt;stdlib.h&gt; <BR>#include &lt;stdio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; int number = 12345; 
      <BR>&nbsp;&nbsp; char string[25]; <BR>
      <P>&nbsp;&nbsp; itoa(number, string, 10); <BR>&nbsp;&nbsp; printf("integer 
      = %d string = %s\n", number, string); <BR>&nbsp;&nbsp; return 0; <BR>} 
      <BR>&nbsp; <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 + -