📄 fg.htm
字号:
<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>fg</title>
</head>
<body>
<p> </p>
<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">导航条:--></font> <a
href="../../index.html">网上学堂</a> --> <a
href="../tcindex.htm"><font face="宋体">C</font>语言编程宝典之一</a>
--></td>
</tr>
<tr>
<td bordercolor="#8080FF" class="p9">
<p>函数名: gcvt <br>
功 能: 把浮点数转换成字符串 <br>
用 法: char *gcvt(double value, int ndigit, char *buf); <br>
程序例: </p>
<p>#include <stdlib.h> <br>
#include <stdio.h> </p>
<p>int main(void) <br>
{ <br>
char str[25]; <br>
double num; <br>
int sig = 5; /* significant digits */ </p>
<p> /* a regular number */ <br>
num = 9.876; <br>
gcvt(num, sig, str); <br>
printf("string = %s\n", str); </p>
<p> /* a negative number */ <br>
num = -123.4567; <br>
gcvt(num, sig, str); <br>
printf("string = %s\n", str); </p>
<p> /* scientific notation */ <br>
num = 0.678e5; <br>
gcvt(num, sig, str); <br>
printf("string = %s\n", str); </p>
<p> return(0); <br>
} <br>
<br>
<br>
</p>
<p>函数名: geninterrupt <br>
功 能: 产生一个软中断 <br>
用 法: void geninterrupt(int intr_num); <br>
程序例: </p>
<p>#include <conio.h> <br>
#include <dos.h> </p>
<p>/* function prototype */ <br>
void writechar(char ch); </p>
<p>int main(void) <br>
{ <br>
clrscr(); <br>
gotoxy(80,25); <br>
writechar('*'); <br>
getch(); <br>
return 0; <br>
} </p>
<p>/* <br>
outputs a character at the current cursor <br>
position using the video BIOS to avoid the <br>
scrolling of the screen when writing to <br>
location (80,25). <br>
*/ </p>
<p>void writechar(char ch) <br>
{ <br>
struct text_info ti; <br>
/* grab current text settings */ <br>
gettextinfo(&ti); <br>
/* interrupt 0x10 sub-function 9 */ <br>
_AH = 9; <br>
/* character to be output */ <br>
_AL = ch; <br>
_BH = 0;
/* video page */ <br>
_BL = ti.attribute; /* video attribute */ <br>
_CX = 1;
/* repetition factor */ <br>
geninterrupt(0x10); /* output the char */ <br>
} <br>
<br>
</p>
<p>函数名: getarccoords <br>
功 能: 取得最后一次调用arc的坐标 <br>
用 法: void far getarccoords(struct arccoordstype far
*arccoords); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
struct arccoordstype arcinfo; <br>
int midx, midy; <br>
int stangle = 45, endangle = 270; <br>
char sstr[80], estr[80]; </p>
<p>/* initialize graphics and local variables */ <br>
initgraph(&gdriver, &gmode, ""); </p>
<p>/* read result of initialization */ <br>
errorcode = graphresult(); <br>
/* an error occurred */ <br>
if (errorcode != grOk) <br>
{ <br>
printf("Graphics error:
%s\n", <br>
grapherrormsg(errorcode)); <br>
printf("Press any key to
halt:"); <br>
getch(); <br>
/* terminate with an error code */ <br>
exit(1); <br>
} </p>
<p> midx = getmaxx() / 2; <br>
midy = getmaxy() / 2; </p>
<p>/* draw arc and get coordinates */ <br>
setcolor(getmaxcolor()); <br>
arc(midx, midy, stangle, endangle, 100); <br>
getarccoords(&arcinfo); </p>
<p>/* convert arc information into strings */ <br>
sprintf(sstr, "*- (%d, %d)", <br>
arcinfo.xstart, arcinfo.ystart); <br>
sprintf(estr, "*- (%d, %d)", <br>
arcinfo.xend, arcinfo.yend); </p>
<p> /* output the arc information */ <br>
outtextxy(arcinfo.xstart, <br>
arcinfo.ystart, sstr); <br>
outtextxy(arcinfo.xend, <br>
arcinfo.yend, estr); </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: getaspectratio <br>
功 能: 返回当前图形模式的纵横比 <br>
用 法: void far getaspectratio(int far *xasp, int far
*yasp); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
int xasp, yasp, midx, midy; </p>
<p>/* initialize graphics and local variables */ <br>
initgraph(&gdriver, &gmode, ""); </p>
<p>/* read result of initialization */ <br>
errorcode = graphresult(); <br>
/* an error occurred */ <br>
if (errorcode != grOk) <br>
{ <br>
printf("Graphics error:
%s\n", <br>
grapherrormsg(errorcode)); <br>
printf("Press any key to
halt:"); <br>
getch(); <br>
/* terminate with an error code */ <br>
exit(1); <br>
} </p>
<p> midx = getmaxx() / 2; <br>
midy = getmaxy() / 2; <br>
setcolor(getmaxcolor()); </p>
<p>/* get current aspect ratio settings */ <br>
getaspectratio(&xasp, &yasp); </p>
<p>/* draw normal circle */ <br>
circle(midx, midy, 100); <br>
getch(); </p>
<p>/* draw wide circle */ <br>
cleardevice(); <br>
setaspectratio(xasp/2, yasp); <br>
circle(midx, midy, 100); <br>
getch(); </p>
<p>/* draw narrow circle */ <br>
cleardevice(); <br>
setaspectratio(xasp, yasp/2); <br>
circle(midx, midy, 100); </p>
<p>/* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: getbkcolor <br>
功 能: 返回当前背景颜色 <br>
用 法: int far getbkcolor(void); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <string.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
int bkcolor, midx, midy; <br>
char bkname[35]; </p>
<p>/* initialize graphics and local variables */ <br>
initgraph(&gdriver, &gmode, ""); </p>
<p>/* read result of initialization */ <br>
errorcode = graphresult(); <br>
/* an error occurred */ <br>
if (errorcode != grOk) <br>
{ <br>
printf("Graphics error:
%s\n", <br>
grapherrormsg(errorcode)); <br>
printf("Press any key to
halt:"); <br>
getch(); <br>
/* terminate with an error code */ <br>
exit(1); <br>
} </p>
<p> midx = getmaxx() / 2; <br>
midy = getmaxy() / 2; <br>
setcolor(getmaxcolor()); </p>
<p>/* for centering text on the display */ <br>
settextjustify(CENTER_TEXT, CENTER_TEXT); </p>
<p>/* get the current background color */ <br>
bkcolor = getbkcolor(); </p>
<p>/* convert color value into a string */ <br>
itoa(bkcolor, bkname, 10); <br>
strcat(bkname, <br>
" is the current background color."); </p>
<p>/* display a message */ <br>
outtextxy(midx, midy, bkname); </p>
<p>/* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: getc <br>
功 能: 从流中取字符 <br>
用 法: int getc(FILE *stream); <br>
程序例: </p>
<p>#include <stdio.h> </p>
<p>int main(void) <br>
{ <br>
char ch; </p>
<p> printf("Input a character:"); <br>
/* read a character from the <br>
standard input stream */ <br>
ch = getc(stdin); <br>
printf("The character input was: '%c'\n", <br>
ch); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: getcbrk <br>
功 能: 获取Control_break设置 <br>
用 法: int getcbrk(void); <br>
程序例: </p>
<p>#include <stdio.h> <br>
#include <dos.h> </p>
<p>int main(void) <br>
{ <br>
if (getcbrk()) <br>
printf("Cntrl-brk flag is
on\n"); <br>
else <br>
printf("Cntrl-brk flag is
off\n"); </p>
<p> return 0; <br>
} <br>
<br>
</p>
<p>函数名: getch <br>
功 能: 从控制台无回显地取一个字符 <br>
用 法: int getch(void); <br>
程序例: </p>
<p>#include <stdio.h> <br>
#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
char ch; </p>
<p> printf("Input a character:"); <br>
ch = getche(); <br>
printf("\nYou input a '%c'\n", ch); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: getchar <br>
功 能: 从stdin流中读字符 <br>
用 法: int getchar(void); <br>
程序例: </p>
<p>#include <stdio.h> </p>
<p>int main(void) <br>
{ <br>
int c; </p>
<p> /* Note that getchar reads from stdin and <br>
is line buffered; this means it
will <br>
not return until you press ENTER.
*/ </p>
<p> while ((c = getchar()) != '\n') <br>
printf("%c", c); </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -