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

📄 fi.htm

📁 c语言基本的应用便于初学者学习使用 简单易懂
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb_2312-80">
<meta name="Author" content="wdg">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>网上学堂 --> C语言编程宝典之一 -->函数名: i</title>
</head>

<body>
<div align="center"><center>

<table border="1" cellpadding="4" width="640"
bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF">
    <tr>
        <td bgcolor="#FFE6B0" bordercolor="#8080FF" class="p9"><font
        color="#BB0000">导航条:--&gt;</font> <a
        href="../../index.html">网上学堂</a> --&gt; <a
        href="../tcindex.htm"><font face="宋体">C</font>语言编程宝典之一</a>
        --&gt;函数名: i</td>
    </tr>
    <tr>
        <td bordercolor="#8080FF" class="p9">函数名: imagesize
        <br>
        功&nbsp; 能: 返回保存位图像所需的字节数 <br>
        用&nbsp; 法: unsigned far imagesize(int left, int top,
        int right, int bottom); <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; </p>
        <p>#define ARROW_SIZE 10 </p>
        <p>void draw_arrow(int x, int y); </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; /* request autodetection */ <br>
        &nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <br>
        &nbsp;&nbsp; void *arrow; <br>
        &nbsp;&nbsp; int x, y, maxx; <br>
        &nbsp;&nbsp; unsigned int size; </p>
        <p>&nbsp;&nbsp; /* initialize graphics and local
        variables */ <br>
        &nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode,
        &quot;&quot;); </p>
        <p>&nbsp;&nbsp; /* read result of initialization */ <br>
        &nbsp;&nbsp; errorcode = graphresult(); <br>
        &nbsp;&nbsp; if (errorcode != grOk)&nbsp; /* an error
        occurred */ <br>
        &nbsp;&nbsp; { <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;Graphics
        error: %s\n&quot;, grapherrormsg(errorcode)); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;Press any key
        to halt:&quot;); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with
        an error code */ <br>
        &nbsp;&nbsp; } </p>
        <p>&nbsp;&nbsp; maxx = getmaxx(); <br>
        &nbsp;&nbsp; x = 0; <br>
        &nbsp;&nbsp; y = getmaxy() / 2; </p>
        <p>&nbsp;&nbsp; /* draw the image to be grabbed */ <br>
        &nbsp;&nbsp; draw_arrow(x, y); </p>
        <p>&nbsp;&nbsp; /* calculate the size of the image */ <br>
        &nbsp;&nbsp; size = imagesize(x, y-ARROW_SIZE,
        x+(4*ARROW_SIZE), y+ARROW_SIZE); </p>
        <p>&nbsp;&nbsp; /* allocate memory to hold the image */ <br>
        &nbsp;&nbsp; arrow = malloc(size); </p>
        <p>&nbsp;&nbsp; /* grab the image */ <br>
        &nbsp;&nbsp; getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE),
        y+ARROW_SIZE, arrow); </p>
        <p>&nbsp;&nbsp; /* repeat until a key is pressed */ <br>
        &nbsp;&nbsp; while (!kbhit()) <br>
        &nbsp;&nbsp; { <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* erase old image */ <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putimage(x, y-ARROW_SIZE,
        arrow, XOR_PUT); </p>
        <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x += ARROW_SIZE; <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (x &gt;= maxx) <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x
        = 0; </p>
        <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* plot new image */ <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putimage(x, y-ARROW_SIZE,
        arrow, XOR_PUT); <br>
        &nbsp;&nbsp; } </p>
        <p>&nbsp;&nbsp; /* clean up */ <br>
        &nbsp;&nbsp; free(arrow); <br>
        &nbsp;&nbsp; closegraph(); <br>
        &nbsp;&nbsp; return 0; <br>
        } </p>
        <p>void draw_arrow(int x, int y) <br>
        { <br>
        &nbsp;&nbsp; /* draw an arrow on the screen */ <br>
        &nbsp;&nbsp; moveto(x, y); <br>
        &nbsp;&nbsp; linerel(4*ARROW_SIZE, 0); <br>
        &nbsp;&nbsp; linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); <br>
        &nbsp;&nbsp; linerel(0, 2*ARROW_SIZE); <br>
        &nbsp;&nbsp; linerel(2*ARROW_SIZE, -1*ARROW_SIZE); <br>
        } <br>
        &nbsp; <br>
        &nbsp; <br>
        &nbsp; </p>
        <p>函数名: initgraph <br>
        功&nbsp; 能: 初始化图形系统 <br>
        用&nbsp; 法: void far initgraph(int far *graphdriver,
        int far *graphmode, <br>
        &nbsp;&nbsp;&nbsp; char far *pathtodriver); <br>
        程序例: </p>
        <p>#include &lt;graphics.h&gt; <br>
        #include &lt;stdlib.h&gt; <br>
        #include &lt;stdio.h&gt; <br>
        #include &lt;conio.h&gt; </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; /* request auto detection */ <br>
        &nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; </p>
        <p>&nbsp;&nbsp; /* initialize graphics mode */ <br>
        &nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode,
        &quot;&quot;); </p>
        <p>&nbsp;&nbsp; /* read result of initialization */ <br>
        &nbsp;&nbsp; errorcode = graphresult(); </p>
        <p>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; /* an error
        occurred */ <br>
        &nbsp;&nbsp; { <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;Graphics
        error: %s\n&quot;, grapherrormsg(errorcode)); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;Press any key
        to halt:&quot;); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        /* return with error code */ <br>
        &nbsp;&nbsp; } </p>
        <p>&nbsp;&nbsp; /* draw a line */ <br>
        &nbsp;&nbsp; line(0, 0, getmaxx(), getmaxy()); </p>
        <p>&nbsp;&nbsp; /* clean up */ <br>
        &nbsp;&nbsp; getch(); <br>
        &nbsp;&nbsp; closegraph(); <br>
        &nbsp;&nbsp; return 0; <br>
        } <br>
        &nbsp; <br>
        &nbsp; </p>
        <p>函数名: inport <br>
        功&nbsp; 能: 从硬件端口中输入 <br>
        用&nbsp; 法: int inp(int protid); <br>
        程序例: </p>
        <p>#include &lt;stdio.h&gt; <br>
        #include &lt;dos.h&gt; </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; int result; <br>
        &nbsp;&nbsp; int port = 0;&nbsp; /* serial port 0 */ </p>
        <p>&nbsp;&nbsp; result = inport(port); <br>
        &nbsp;&nbsp; printf(&quot;Word read from port %d =
        0x%X\n&quot;, port, result); <br>
        &nbsp;&nbsp; return 0; <br>
        } <br>
        &nbsp; <br>
        &nbsp; </p>
        <p>函数名: insline <br>
        功&nbsp; 能: 在文本窗口中插入一个空行 <br>
        用&nbsp; 法: void insline(void); <br>
        程序例: </p>
        <p>#include &lt;conio.h&gt; </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; clrscr(); <br>
        &nbsp;&nbsp; cprintf(&quot;INSLINE inserts an empty line
        in the text window\r\n&quot;); <br>
        &nbsp;&nbsp; cprintf(&quot;at the cursor position using
        the current text\r\n&quot;); <br>
        &nbsp;&nbsp; cprintf(&quot;background color.&nbsp; All
        lines below the empty one\r\n&quot;); <br>
        &nbsp;&nbsp; cprintf(&quot;move down one line and the
        bottom line scrolls\r\n&quot;); <br>
        &nbsp;&nbsp; cprintf(&quot;off the bottom of the
        window.\r\n&quot;); <br>
        &nbsp;&nbsp; cprintf(&quot;\r\nPress any key to
        continue:&quot;); <br>
        &nbsp;&nbsp; gotoxy(1, 3); <br>
        &nbsp;&nbsp; getch(); <br>
        &nbsp;&nbsp; insline(); <br>
        &nbsp;&nbsp; getch(); <br>
        &nbsp;&nbsp; return 0; <br>
        } <br>
        &nbsp; <br>
        &nbsp; <br>
        &nbsp; </p>
        <p>函数名: installuserdriver <br>
        功&nbsp; 能: 安装设备驱动程序到BGI设备驱动程序表中
        <br>
        用&nbsp; 法: int far installuserdriver(char far *name,
        int (*detect)(void)); <br>
        程序例: </p>
        <p>#include &lt;graphics.h&gt; <br>
        #include &lt;stdlib.h&gt; <br>
        #include &lt;stdio.h&gt; <br>
        #include &lt;conio.h&gt; </p>
        <p>/* function prototypes */ <br>
        int huge detectEGA(void); <br>
        void checkerrors(void); </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; int gdriver, gmode; </p>
        <p>&nbsp;&nbsp; /* install a user written device driver
        */ <br>
        &nbsp;&nbsp; gdriver = installuserdriver(&quot;EGA&quot;,
        detectEGA); </p>
        <p>&nbsp;&nbsp; /* must force use of detection routine */
        <br>
        &nbsp;&nbsp; gdriver = DETECT; </p>
        <p>&nbsp;&nbsp; /* check for any installation errors */ <br>
        &nbsp;&nbsp; checkerrors(); </p>
        <p>&nbsp;&nbsp; /* initialize graphics and local
        variables */ <br>
        &nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode,
        &quot;&quot;); </p>
        <p>&nbsp;&nbsp; /* check for any initialization errors */
        <br>
        &nbsp;&nbsp; checkerrors(); </p>
        <p>&nbsp;&nbsp; /* draw a line */ <br>
        &nbsp;&nbsp; line(0, 0, getmaxx(), getmaxy()); </p>
        <p>&nbsp;&nbsp; /* clean up */ <br>
        &nbsp;&nbsp; getch(); <br>
        &nbsp;&nbsp; closegraph(); <br>
        &nbsp;&nbsp; return 0; <br>
        } </p>
        <p>/* detects EGA or VGA cards */ <br>
        int huge detectEGA(void) <br>
        { <br>
        &nbsp;&nbsp; int driver, mode, sugmode = 0; </p>
        <p>&nbsp;&nbsp; detectgraph(&amp;driver, &amp;mode); <br>
        &nbsp;&nbsp; if ((driver == EGA) || (driver == VGA)) <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* return suggested video
        mode number */ <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return sugmode; <br>
        &nbsp;&nbsp; else <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* return an error code */
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return grError; <br>
        } </p>
        <p>/* check for and report any graphics errors */ <br>
        void checkerrors(void) <br>
        { <br>
        &nbsp;&nbsp; int errorcode; </p>
        <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(&quot;Graphics
        error: %s\n&quot;, grapherrormsg(errorcode)); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;Press any key
        to halt:&quot;); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <br>
        &nbsp;&nbsp; } <br>
        } </p>
        <p>函数名: installuserfont <br>
        功&nbsp; 能: 安装未嵌入BGI系统的字体文件(CHR)
        <br>
        用&nbsp; 法: int far installuserfont(char far *name); <br>
        程序例: </p>
        <p>#include &lt;graphics.h&gt; <br>
        #include &lt;stdlib.h&gt; <br>
        #include &lt;stdio.h&gt; <br>
        #include &lt;conio.h&gt; </p>
        <p>/* function prototype */ <br>
        void checkerrors(void); </p>
        <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; </p>
        <p>&nbsp;&nbsp; /* initialize graphics and local
        variables */ <br>
        &nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode,
        &quot;&quot;); </p>
        <p>&nbsp;&nbsp; midx = getmaxx() / 2; <br>
        &nbsp;&nbsp; midy = getmaxy() / 2; </p>
        <p>&nbsp;&nbsp; /* check for any initialization errors */
        <br>
        &nbsp;&nbsp; checkerrors(); </p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -