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

📄 fr.htm

📁 turbo c
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: rectangle<BR>功&nbsp; 能: 画一个矩形<BR>用&nbsp; 法: void far rectangle(int left, int top, int right, int bottom);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; int left, top, right, bottom;<P>&nbsp;&nbsp; /* initialize graphics and local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<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("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); /* terminate with an errorcode */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; left = getmaxx() / 2 - 50;<BR>&nbsp;&nbsp; top = getmaxy() / 2 - 50;<BR>&nbsp;&nbsp; right = getmaxx() / 2 + 50;<BR>&nbsp;&nbsp; bottom = getmaxy() / 2 + 50;<P>&nbsp;&nbsp; /* draw a rectangle */<BR>&nbsp;&nbsp; rectangle(left,top,right,bottom);<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: registerbgidriver<BR>功&nbsp; 能: 登录已连接进来的图形驱动程序代码<BR>用&nbsp; 法: int registerbgidriver(void(*driver)(void));<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<P>&nbsp;&nbsp; /* register a driver that was added into graphics.lib */<BR>&nbsp;&nbsp; errorcode = registerbgidriver(EGAVGA_driver);<P>&nbsp;&nbsp; /* report any registration errors */<BR>&nbsp;&nbsp; if (errorcode &lt; 0)<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); /* terminate with an errorcode */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; /* initialize graphics and local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<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("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); /* terminate with an errorcode */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; /* draw a line */<BR>&nbsp;&nbsp; line(0, 0, getmaxx(), getmaxy());<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: remove<BR>功&nbsp; 能: 删除一个文件<BR>用&nbsp; 法: int remove(char *filename);<BR>程序例:<P>#include &lt;stdio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; char file[80];<P>&nbsp;&nbsp; /* prompt for file name to delete */<BR>&nbsp;&nbsp; printf("File to delete: ");<BR>&nbsp;&nbsp; gets(file);<P>&nbsp;&nbsp; /* delete the file */<BR>&nbsp;&nbsp; if (remove(file) == 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Removed %s.\n",file);<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("remove");<P>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: rename<BR>功&nbsp; 能: 重命名文件<BR>用&nbsp; 法: int rename(char *oldname, char *newname);<BR>程序例:<P>#include &lt;stdio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; char oldname[80], newname[80];<P>&nbsp;&nbsp; /* prompt for file to rename and new name */<BR>&nbsp;&nbsp; printf("File to rename: ");<BR>&nbsp;&nbsp; gets(oldname);<BR>&nbsp;&nbsp; printf("New name: ");<BR>&nbsp;&nbsp; gets(newname);<P>&nbsp;&nbsp; /* Rename the file */<BR>&nbsp;&nbsp; if (rename(oldname, newname) == 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Renamed %s to %s.\n", oldname,newname);<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("rename");<P>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: restorecrtmode<BR>功&nbsp; 能: 将屏幕模式恢复为先前的imitgraph设置<BR>用&nbsp; 法: void far restorecrtmode(void);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; int x, y;<P>&nbsp;&nbsp; /* initialize graphics and local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<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("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); /* terminate with an errorcode */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; x = getmaxx() / 2;<BR>&nbsp;&nbsp; y = getmaxy() / 2;<P>&nbsp;&nbsp; /* output a message */<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);<BR>&nbsp;&nbsp; outtextxy(x, y, "Press any key to exit graphics:");<BR>&nbsp;&nbsp; getch();<P>&nbsp;&nbsp; /* restore system to text mode */<BR>&nbsp;&nbsp; restorecrtmode();<BR>&nbsp;&nbsp; printf("We're now in text mode.\n");<BR>&nbsp;&nbsp; printf("Press any key to return to graphics mode:");<BR>&nbsp;&nbsp; getch();<P>&nbsp;&nbsp; /* return to graphics mode */<BR>&nbsp;&nbsp; setgraphmode(getgraphmode());<P>&nbsp;&nbsp; /* output a message */<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);<BR>&nbsp;&nbsp; outtextxy(x, y, "We're back in graphics mode.");<BR>&nbsp;&nbsp; outtextxy(x, y+textheight("W"), "Press any key to halt:");<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: rewind<BR>功&nbsp; 能: 将文件指针重新指向一个流的开头<BR>用&nbsp; 法: int rewind(FILE *stream);<BR>程序例:<P>#include &lt;stdio.h><BR>#include &lt;dir.h><P>&nbsp;int main(void)<BR>&nbsp;{<BR>&nbsp;&nbsp;&nbsp; FILE *fp;<BR>&nbsp;&nbsp;&nbsp; char *fname = "TXXXXXX", *newname, first;<P>&nbsp;&nbsp;&nbsp; newname = mktemp(fname);<BR>&nbsp;&nbsp;&nbsp; fp = fopen(newname,"w+");<BR>&nbsp;&nbsp;&nbsp; fprintf(fp,"abcdefghijklmnopqrstuvwxyz");<BR>&nbsp;&nbsp;&nbsp; rewind(fp);<BR>&nbsp;&nbsp;&nbsp; fscanf(fp,"%c",&amp;first);<BR>&nbsp;&nbsp;&nbsp; printf("The first character is: %c\n",first);<BR>&nbsp;&nbsp;&nbsp; fclose(fp);<BR>&nbsp;&nbsp;&nbsp; remove(newname);<P>&nbsp;&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: rmdir<BR>功&nbsp; 能: 删除DOS文件目录<BR>用&nbsp; 法: int rmdir(char *stream);<BR>程序例:<P>#include &lt;stdio.h><BR>#include &lt;conio.h><BR>#include &lt;process.h><BR>#include &lt;dir.h><P>#define DIRNAME "testdir.$$$"<P>int main(void)<BR>{<BR>&nbsp;&nbsp; int stat;<P>&nbsp;&nbsp; stat = mkdir(DIRNAME);<BR>&nbsp;&nbsp; if (!stat)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Directorycreated\n");<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Unable to create directory\n");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; system("dir/p");<BR>&nbsp;&nbsp; getch();<P>&nbsp;&nbsp; stat = rmdir(DIRNAME);<BR>&nbsp;&nbsp; if (!stat)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("\nDirectorydeleted\n");<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp; perror("\nUnable to delete directory\n");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<P>&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;&nbsp;<A HREF="index.html">返回目录</A><BR></BODY></HTML>

⌨️ 快捷键说明

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