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

📄 fg.htm

📁 C程序宝藏,内有标准C的详细介绍,适合自学,初学人员参考
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
   <META NAME="Author" CONTENT="wdg">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.03 [en] (Win95; I) [Netscape]">
   <TITLE>fg</TITLE>
</HEAD>
<BODY>
&nbsp;

<P>函数名: gcvt
<BR>功&nbsp; 能: 把浮点数转换成字符串
<BR>用&nbsp; 法: char *gcvt(double value, int ndigit, char *buf);
<BR>程序例:

<P>#include &lt;stdlib.h>
<BR>#include &lt;stdio.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; char str[25];
<BR>&nbsp;&nbsp; double num;
<BR>&nbsp;&nbsp; int sig = 5; /* significant digits */

<P>&nbsp;&nbsp; /* a regular number */
<BR>&nbsp;&nbsp; num = 9.876;
<BR>&nbsp;&nbsp; gcvt(num, sig, str);
<BR>&nbsp;&nbsp; printf("string = %s\n", str);

<P>&nbsp;&nbsp; /* a negative number */
<BR>&nbsp;&nbsp; num = -123.4567;
<BR>&nbsp;&nbsp; gcvt(num, sig, str);
<BR>&nbsp;&nbsp; printf("string = %s\n", str);

<P>&nbsp;&nbsp; /* scientific notation */
<BR>&nbsp;&nbsp; num = 0.678e5;
<BR>&nbsp;&nbsp; gcvt(num, sig, str);
<BR>&nbsp;&nbsp; printf("string = %s\n", str);

<P>&nbsp;&nbsp; return(0);
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: geninterrupt
<BR>功&nbsp; 能: 产生一个软中断
<BR>用&nbsp; 法: void geninterrupt(int intr_num);
<BR>程序例:

<P>#include &lt;conio.h>
<BR>#include &lt;dos.h>

<P>/* function prototype */
<BR>void writechar(char ch);

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; clrscr();
<BR>&nbsp;&nbsp; gotoxy(80,25);
<BR>&nbsp;&nbsp; writechar('*');
<BR>&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; return 0;
<BR>}

<P>/*
<BR>&nbsp;&nbsp; outputs a character at the current cursor
<BR>&nbsp;&nbsp; position using the video BIOS to avoid the
<BR>&nbsp;&nbsp; scrolling of the screen when writing to
<BR>&nbsp;&nbsp; location (80,25).
<BR>*/

<P>void writechar(char ch)
<BR>{
<BR>&nbsp;&nbsp; struct text_info ti;
<BR>&nbsp;&nbsp; /* grab current text settings */
<BR>&nbsp;&nbsp; gettextinfo(&amp;ti);
<BR>&nbsp;&nbsp; /* interrupt 0x10 sub-function 9 */
<BR>&nbsp;&nbsp; _AH = 9;
<BR>&nbsp;&nbsp; /* character to be output */
<BR>&nbsp;&nbsp; _AL = ch;
<BR>&nbsp;&nbsp; _BH = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* video page */
<BR>&nbsp;&nbsp; _BL = ti.attribute;&nbsp; /* video attribute */
<BR>&nbsp;&nbsp; _CX = 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/* repetition factor */
<BR>&nbsp;&nbsp; geninterrupt(0x10);&nbsp; /* output the char */
<BR>}
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: getarccoords
<BR>功&nbsp; 能: 取得最后一次调用arc的坐标
<BR>用&nbsp; 法: void far getarccoords(struct arccoordstype far *arccoords);
<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>/* request auto detection */
<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;
<BR>&nbsp;&nbsp; struct arccoordstype arcinfo;
<BR>&nbsp;&nbsp; int midx, midy;
<BR>&nbsp;&nbsp; int stangle = 45, endangle = 270;
<BR>&nbsp;&nbsp; char sstr[80], estr[80];

<P>/* initialize graphics and local variables */
<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");

<P>/* read result of initialization */
<BR>&nbsp;&nbsp; errorcode = graphresult();
<BR>/* an error occurred */
<BR>&nbsp;&nbsp; if (errorcode != grOk)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
grapherrormsg(errorcode));
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();
<BR>/* terminate with an error code */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);
<BR>&nbsp;&nbsp; }

<P>&nbsp;&nbsp; midx = getmaxx() / 2;
<BR>&nbsp;&nbsp; midy = getmaxy() / 2;

<P>/* draw arc and get coordinates */
<BR>&nbsp;&nbsp; setcolor(getmaxcolor());
<BR>&nbsp;&nbsp; arc(midx, midy, stangle, endangle, 100);
<BR>&nbsp;&nbsp; getarccoords(&amp;arcinfo);

<P>/* convert arc information into strings */
<BR>&nbsp;&nbsp; sprintf(sstr, "*- (%d, %d)",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arcinfo.xstart,
arcinfo.ystart);
<BR>&nbsp;&nbsp; sprintf(estr, "*- (%d, %d)",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arcinfo.xend,
arcinfo.yend);

<P>&nbsp;&nbsp; /* output the arc information */
<BR>&nbsp;&nbsp; outtextxy(arcinfo.xstart,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
arcinfo.ystart, sstr);
<BR>&nbsp;&nbsp; outtextxy(arcinfo.xend,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
arcinfo.yend, estr);

<P>&nbsp;&nbsp; /* clean up */
<BR>&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; closegraph();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: getaspectratio
<BR>功&nbsp; 能: 返回当前图形模式的纵横比
<BR>用&nbsp; 法: void far getaspectratio(int far *xasp, int far *yasp);
<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>/* request auto detection */
<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;
<BR>&nbsp;&nbsp; int xasp, yasp, midx, midy;

<P>/* initialize graphics and local variables */
<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");

<P>/* read result of initialization */
<BR>&nbsp;&nbsp; errorcode = graphresult();
<BR>/* an error occurred */
<BR>&nbsp;&nbsp; if (errorcode != grOk)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
grapherrormsg(errorcode));
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();
<BR>/* terminate with an error code */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);
<BR>&nbsp;&nbsp; }

<P>&nbsp;&nbsp; midx = getmaxx() / 2;
<BR>&nbsp;&nbsp; midy = getmaxy() / 2;
<BR>&nbsp;&nbsp; setcolor(getmaxcolor());

<P>/* get current aspect ratio settings */
<BR>&nbsp;&nbsp; getaspectratio(&amp;xasp, &amp;yasp);

<P>/* draw normal circle */
<BR>&nbsp;&nbsp; circle(midx, midy, 100);
<BR>&nbsp;&nbsp; getch();

<P>/* draw wide circle */
<BR>&nbsp;&nbsp; cleardevice();
<BR>&nbsp;&nbsp; setaspectratio(xasp/2, yasp);
<BR>&nbsp;&nbsp; circle(midx, midy, 100);
<BR>&nbsp;&nbsp; getch();

<P>/* draw narrow circle */
<BR>&nbsp;&nbsp; cleardevice();
<BR>&nbsp;&nbsp; setaspectratio(xasp, yasp/2);
<BR>&nbsp;&nbsp; circle(midx, midy, 100);

<P>/* clean up */
<BR>&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; closegraph();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: getbkcolor
<BR>功&nbsp; 能: 返回当前背景颜色
<BR>用&nbsp; 法: int far getbkcolor(void);
<BR>程序例:

<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;string.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 bkcolor, midx, midy;
<BR>&nbsp;&nbsp; char bkname[35];

<P>/* initialize graphics and local variables */
<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");

<P>/* read result of initialization */
<BR>&nbsp;&nbsp; errorcode = graphresult();
<BR>/* an error occurred */
<BR>&nbsp;&nbsp; if (errorcode != grOk)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
grapherrormsg(errorcode));
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();
<BR>/* terminate with an error code */
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);
<BR>&nbsp;&nbsp; }

<P>&nbsp;&nbsp; midx = getmaxx() / 2;
<BR>&nbsp;&nbsp; midy = getmaxy() / 2;
<BR>&nbsp;&nbsp; setcolor(getmaxcolor());

<P>/* for centering text on the display */
<BR>&nbsp;&nbsp; settextjustify(CENTER_TEXT, CENTER_TEXT);

<P>/* get the current background color */
<BR>&nbsp;&nbsp; bkcolor = getbkcolor();

<P>/* convert color value into a string */
<BR>&nbsp;&nbsp; itoa(bkcolor, bkname, 10);
<BR>&nbsp;&nbsp; strcat(bkname,
<BR>&nbsp;" is the current background color.");

<P>/* display a message */
<BR>&nbsp;&nbsp; outtextxy(midx, midy, bkname);

<P>/* clean up */
<BR>&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; closegraph();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: getc
<BR>功&nbsp; 能: 从流中取字符
<BR>用&nbsp; 法: int getc(FILE *stream);
<BR>程序例:

<P>#include &lt;stdio.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; char ch;

<P>&nbsp;&nbsp; printf("Input a character:");
<BR>/* read a character from the
<BR>&nbsp;&nbsp; standard input stream */
<BR>&nbsp;&nbsp; ch = getc(stdin);
<BR>&nbsp;&nbsp; printf("The character input was: '%c'\n",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ch);
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: getcbrk
<BR>功&nbsp; 能: 获取Control_break设置
<BR>用&nbsp; 法: int getcbrk(void);
<BR>程序例:

<P>#include &lt;stdio.h>
<BR>#include &lt;dos.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; if (getcbrk())
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Cntrl-brk flag is on\n");
<BR>&nbsp;&nbsp; else
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Cntrl-brk flag is off\n");

<P>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: getch
<BR>功&nbsp; 能: 从控制台无回显地取一个字符
<BR>用&nbsp; 法: int getch(void);
<BR>程序例:

<P>#include &lt;stdio.h>
<BR>#include &lt;conio.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; char ch;

<P>&nbsp;&nbsp; printf("Input a character:");
<BR>&nbsp;&nbsp; ch = getche();
<BR>&nbsp;&nbsp; printf("\nYou input a '%c'\n", ch);
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: getchar
<BR>功&nbsp; 能: 从stdin流中读字符
<BR>用&nbsp; 法: int getchar(void);
<BR>程序例:

<P>#include &lt;stdio.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; int c;

<P>&nbsp;&nbsp; /* Note that getchar reads from stdin and
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; is line buffered; this means it will
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not return until you press ENTER. */

<P>&nbsp;&nbsp; while ((c = getchar()) != '\n')
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%c", c);

<P>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: getche
<BR>功&nbsp; 能: 从控制台取字符(带回显)
<BR>用&nbsp; 法: int getche(void);
<BR>程序例:

<P>#include &lt;stdio.h>
<BR>#include &lt;conio.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; char ch;

<P>&nbsp;&nbsp; printf("Input a character:");
<BR>&nbsp;&nbsp; ch = getche();
<BR>&nbsp;&nbsp; printf("\nYou input a '%c'\n", ch);
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: getcolor
<BR>功&nbsp; 能: 返回当前画线颜色
<BR>用&nbsp; 法: int far getcolor(void);
<BR>程序例:

<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;string.h>
<BR>#include &lt;stdio.h>

⌨️ 快捷键说明

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