📄 032.htm
字号:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><TITLE>王大刚-->C语言编程宝典-->O</TITLE>
<META NAME="keywords" CONTENT="王大刚 C语言编程宝典 O">
<META NAME="description" CONTENT="王大刚 - C语言编程宝典 - O">
<style>
<!--
#page {position:absolute; z-index:0; left:0px; top:0px}
.tt3 {font: 9pt/12pt "宋体"}
.tt2 {font: 12pt/15pt "宋体"}
a {text-decoration:none}
a:hover {color: blue;text-decoration:underline}
-->
</style>
</HEAD>
<body text="#000000" aLink=#9900ff link=#006699 vLink=#006699 bgcolor="#FFFFFF" leftmargin="3" topmargin="3" marginheight="3" marginwidth="3">
<TABLE WIDTH="100%" CELLPADDING=10 CELLSPACING=0 BORDER=0>
<TR>
<TD CLASS="tt3" VALIGN="top" width="8%" bgcolor="#e0e0e0"><strong><A HREF="033.htm">后一页</A><BR>
<A HREF="031.htm">前一页</A><BR>
<A HREF="index.html">回目录</A><BR>
<A HREF="../../../../index.htm">回首页</A><BR>
</strong>
</TD>
<TD class="tt2" bgcolor="#F5F8F8" width="84%"><center><B><FONT style="FONT-SIZE: 16.5pt" COLOR="#FF6666" FACE="楷体_GB2312">O</FONT></B></center>
<hr color="#EE9B73" size="1" width="94%">
<P>函数名: open
<BR>功 能: 打开一个文件用于读或写
<BR>用 法: int open(char *pathname, int access[, int permiss]);
<BR>程序例:
<BR>
<P>#include <string.h>
<BR>#include <stdio.h>
<BR>#include <fcntl.h>
<BR>#include <io.h>
<BR>
<P>int main(void)
<BR>{
<BR> int handle;
<BR> char msg[] = "Hello world";
<BR>
<P> if ((handle = open("TEST.$$$", O_CREAT | O_TEXT)) == -1)
<BR> {
<BR> perror("Error:");
<BR> return 1;
<BR> }
<BR> write(handle, msg, strlen(msg));
<BR> close(handle);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: outport
<BR>功 能: 输出整数到硬件端口中
<BR>用 法: void outport(int port, int value);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <dos.h>
<BR>
<P>int main(void)
<BR>{
<BR> int value = 64;
<BR> int port = 0;
<BR>
<P> outportb(port, value);
<BR> printf("Value %d sent to port number %d\n", value, port);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: outportb
<BR>功 能: 输出字节到硬件端口中
<BR>用 法: void outportb(int port, char byte);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <dos.h>
<BR>
<P>int main(void)
<BR>{
<BR> int value = 64;
<BR> int port = 0;
<BR>
<P> outportb(port, value);
<BR> printf("Value %d sent to port number %d\n", value, port);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: outtext
<BR>功 能: 在视区显示一个字符串
<BR>用 法: void far outtext(char far *textstring);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int midx, midy;
<BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with an error
code */
<BR> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P> /* move the C.P. to the center of the screen */
<BR> moveto(midx, midy);
<BR>
<P> /* output text starting at the C.P. */
<BR> outtext("This ");
<BR> outtext("is ");
<BR> outtext("a ");
<BR> outtext("test.");
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: outtextxy
<BR>功 能: 在指定位置显示一字符串
<BR>用 法: void far outtextxy(int x, int y, char *textstring);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int midx, midy;
<BR>
<P> /* initialize graphics and local variables */
<BR> initgraph( &gdriver, &gmode, "");
<BR>
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk) /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1); /* terminate with an error
code */
<BR> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR>
<P> /* output text at the center of the screen*/
<BR> /* Note: the C.P. doesn't get changed.*/
<BR> outtextxy(midx, midy, "This is a test.");
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<hr color="#EE9B73" size="1" width="94%">
</TD>
<TD CLASS="tt3" VALIGN="bottom" width="8%" bgcolor="#e0e0e0"><strong><A HREF="033.htm">后一页</A><BR>
<A HREF="031.htm">前一页</A><BR>
<A HREF="index.html">回目录</A><BR>
<A HREF="../../../../index.htm">回首页</A><BR>
</strong>
</TD>
</TR>
</table>
</BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -