数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-9 00:49:34 | 显示全部楼层
<>函数名: inport
功  能: 从硬件端口中输入
用  法: int inp(int protid);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;dos.h&gt; <>int main(void)
{
   int result;
   int port = 0;  /* serial port 0 */ <P>   result = inport(port);
   printf("Word read from port %d = 0x%X\n", port, result);
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-9 00:49:51 | 显示全部楼层
<>函数名: insline
功  能: 在文本窗口中插入一个空行
用  法: void insline(void);
程序例: <>#include &lt;conio.h&gt; <>int main(void)
{
   clrscr();
   cprintf("INSLINE inserts an empty line in the text window\r\n");
   cprintf("at the cursor position using the current text\r\n");
   cprintf("background color.  All lines below the empty one\r\n");
   cprintf("move down one line and the bottom line scrolls\r\n");
   cprintf("off the bottom of the window.\r\n");
   cprintf("\r\nPress any key to continue:");
   gotoxy(1, 3);
   getch();
   insline();
   getch();
   return 0;
}
</P>
 楼主| 发表于 2004-5-9 00:50:08 | 显示全部楼层
<>函数名: installuserdriver
功  能: 安装设备驱动程序到BGI设备驱动程序表中
用  法: int far installuserdriver(char far *name, int (*detect)(void));
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>/* function prototypes */
int huge detectEGA(void);
void checkerrors(void); <P>int main(void)
{
   int gdriver, gmode; <P>   /* install a user written device driver */
   gdriver = installuserdriver("EGA", detectEGA); <P>   /* must force use of detection routine */
   gdriver = DETECT; <P>   /* check for any installation errors */
   checkerrors(); <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* check for any initialization errors */
   checkerrors(); <P>   /* draw a line */
   line(0, 0, getmaxx(), getmaxy()); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
} <P>/* detects EGA or VGA cards */
int huge detectEGA(void)
{
   int driver, mode, sugmode = 0; <P>   detectgraph(&amp;driver, &amp;mode);
   if ((driver == EGA) || (driver == VGA))
      /* return suggested video mode number */
      return sugmode;
   else
      /* return an error code */
      return grError;
} <P>/* check for and report any graphics errors */
void checkerrors(void)
{
   int errorcode; <P>   /* read result of last graphics operation */
   errorcode = graphresult();
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }
} </P>
 楼主| 发表于 2004-5-9 00:50:25 | 显示全部楼层
<>函数名: installuserfont
功  能: 安装未嵌入BGI系统的字体文件(CHR)
用  法: int far installuserfont(char far *name);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>/* function prototype */
void checkerrors(void); <P>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode;
   int userfont;
   int midx, midy; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>   /* check for any initialization errors */
   checkerrors(); <P>   /* install a user defined font file */
   userfont = installuserfont("USER.CHR"); <P>   /* check for any installation errors */
   checkerrors(); <P>   /* select the user font */
   settextstyle(userfont, HORIZ_DIR, 4); <P>   /* output some text */
   outtextxy(midx, midy, "Testing!"); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
} <P>/* check for and report any graphics errors */
void checkerrors(void)
{
   int errorcode; <P>   /* read result of last graphics operation */
   errorcode = graphresult();
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }
}
</P>
 楼主| 发表于 2004-5-9 00:50:40 | 显示全部楼层
<>函数名: int86
功  能: 通用8086软中断接口
用  法: int int86(int intr_num, union REGS *inregs, union REGS *outregs);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;dos.h&gt; <>#define VIDEO 0x10 <P>void movetoxy(int x, int y)
{
   union REGS regs; <P>   regs.h.ah = 2;  /* set cursor postion */
   regs.h.dh = y;
   regs.h.dl = x;
   regs.h.bh = 0;  /* video page 0 */
   int86(VIDEO, &amp;regs, &amp;regs);
} <P>int main(void)
{
   clrscr();
   movetoxy(35, 10);
   printf("Hello\n");
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-9 00:51:07 | 显示全部楼层
<>函数名: int86x
功  能: 通用8086软中断接口
用  法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs,
     struct SREGS *segregs);
程序例: <>#include &lt;dos.h&gt;
#include &lt;process.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
   char filename[80];
   union REGS inregs, outregs;
   struct SREGS segregs; <P>   printf("Enter filename: ");
   gets(filename);
   inregs.h.ah = 0x43;
   inregs.h.al = 0x21;
   inregs.x.dx = FP_OFF(filename);
   segregs.ds = FP_SEG(filename);
   int86x(0x21, &amp;inregs, &amp;outregs, &amp;segregs);
   printf("File attribute: %X\n", outregs.x.cx);
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-9 00:51:27 | 显示全部楼层
<>函数名: intdos
功  能: 通用DOS接口
用  法: int intdos(union REGS *inregs, union REGS *outregs);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;dos.h&gt; <>/* deletes file name; returns 0 on success, nonzero on failure */
int delete_file(char near *filename)
{
   union REGS regs;
   int ret;
   regs.h.ah = 0x41;                            /* delete file */
   regs.x.dx = (unsigned) filename;
   ret = intdos(&amp;regs, &amp;regs); <P>   /* if carry flag is set, there was an error */
   return(regs.x.cflag ? ret : 0);
} <P>int main(void)
{
   int err;
   err = delete_file("NOTEXIST.$$$");
   if (!err)
      printf("Able to delete NOTEXIST.$$$\n");
   else
      printf("Not Able to delete NOTEXIST.$$$\n");
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-9 00:51:47 | 显示全部楼层
<>函数名: intdosx
功  能: 通用DOS中断接口
用  法: int intdosx(union REGS *inregs, union REGS *outregs,
      struct SREGS *segregs);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;dos.h&gt; <>/* deletes file name; returns 0 on success, nonzero on failure */
int delete_file(char far *filename)
{
   union REGS regs; struct SREGS sregs;
   int ret;
   regs.h.ah = 0x41;                      /* delete file */
   regs.x.dx = FP_OFF(filename);
   sregs.ds = FP_SEG(filename);
   ret = intdosx(&amp;regs, &amp;regs, &amp;sregs); <P>   /* if carry flag is set, there was an error */
   return(regs.x.cflag ? ret : 0);
} <P>int main(void)
{
   int err;
   err = delete_file("NOTEXIST.$$$");
   if (!err)
      printf("Able to delete NOTEXIST.$$$\n");
   else
      printf("Not Able to delete NOTEXIST.$$$\n");
   return 0;
}
  
  </P>
 楼主| 发表于 2004-5-9 00:52:03 | 显示全部楼层
<>函数名: intr
功  能: 改变软中断接口
用  法: void intr(int intr_num, struct REGPACK *preg);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;dir.h&gt;
#include &lt;dos.h&gt; <>#define CF 1  /* Carry flag */ <P>int main(void)
{
   char directory[80];
   struct REGPACK reg; <P>   printf("Enter directory to change t ");
   gets(directory);
   reg.r_ax = 0x3B &lt;&lt; 8;         /* shift 3Bh into  AH */
   reg.r_dx = FP_OFF(directory);
   reg.r_ds = FP_SEG(directory);
   intr(0x21, &amp;reg);
   if (reg.r_flags &amp; CF)
      printf("Directory change failed\n");
   getcwd(directory, 80);
   printf("The current directory is: %s\n", directory);
   return 0;
}
</P>
 楼主| 发表于 2004-5-9 00:52:28 | 显示全部楼层
<>函数名: ioctl
功  能: 控制I/O设备
用  法: int ioctl(int handle, int cmd[,int *argdx, int argcx]);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;dir.h&gt;
#include &lt;io.h&gt; <>int main(void)
{
   int stat; <P>   /* use func 8 to determine if the default drive is removable */
   stat = ioctl(0, 8, 0, 0);
   if (!stat)
      printf("Drive %c is removable.\n", getdisk() + 'A');
   else
      printf("Drive %c is not removable.\n", getdisk() + 'A');
   return 0;
}
  
  
</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-11-27 02:48 , Processed in 0.048154 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表