📄 王大刚--c语言编程宝典--s.htm
字号:
<BR>
"CENTER_TEXT",
<BR>
"RIGHT_TEXT"
<BR>
}; <BR>
<P>/* vertical text justification settings */ <BR>char *vjust[] = {
"LEFT_TEXT", <BR> "CENTER_TEXT", <BR>
"RIGHT_TEXT"
<BR>
}; <BR>
<P>int main(void) <BR>{ <BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode; <BR>
int midx, midy, hj, vj; <BR> char msg[80]; <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> /* loop through text justifications */ <BR>
for (hj=LEFT_TEXT; hj<=RIGHT_TEXT; hj++)
<BR> for (vj=LEFT_TEXT; vj<=RIGHT_TEXT;
vj++) <BR> {
<BR> cleardevice();
<BR> /* set the text
justification */ <BR>
settextjustify(hj, vj); <BR>
<P> /* create a message
string */ <BR>
sprintf(msg, "%s %s", hjust[hj], vjust[vj]); <BR>
<P> /* create cross hairs on the screen */ <BR> xat(midx,
midy); <BR>
<P> /* output the message
*/ <BR> outtextxy(midx,
midy, msg); <BR> getch();
<BR> } <BR>
<P> /* clean up */ <BR> closegraph();
<BR> return 0; <BR>} <BR>
<P>/* draw an "x" at (x, y) */ <BR>void xat(int x, int y) <BR>{ <BR>
line(x-4, y, x+4, y); <BR> line(x, y-4, x, y+4); <BR>} <BR>
<BR> <BR>
<P>函数名: settextstyle <BR>功 能: 为图形输出设置当前的文本属性 <BR>用 法: void far
settextstyle (int font, int direction, char size); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>/* the names of the text styles supported */ <BR>char *fname[] = {
"DEFAULT font",
<BR>
"TRIPLEX font",
<BR>
"SMALL font",
<BR>
"SANS SERIF font",
<BR>
"GOTHIC font"
<BR>
}; <BR>
<P>int main(void) <BR>{ <BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode; <BR>
int style, midx, midy; <BR> int size = 1; <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> settextjustify(CENTER_TEXT, CENTER_TEXT); <BR>
<P> /* loop through the available text styles */
<BR> for (style=DEFAULT_FONT; style<=GOTHIC_FONT; style++)
<BR> { <BR> cleardevice();
<BR> if (style == TRIPLEX_FONT)
<BR> size = 4; <BR>
<P> /* select the text style */
<BR> settextstyle(style, HORIZ_DIR, size);
<BR>
<P> /* output a message */
<BR> outtextxy(midx, midy, fname[style]);
<BR> getch(); <BR> } <BR>
<P> /* clean up */ <BR> closegraph();
<BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: settextstyle <BR>功 能: 为图形输出设置当前的文本属性 <BR>用 法: void far
settextstyle (int font, int direction, char size); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>/* the names of the text styles supported */ <BR>char *fname[] = {
"DEFAULT font",
<BR>
"TRIPLEX font",
<BR>
"SMALL font",
<BR>
"SANS SERIF font",
<BR>
"GOTHIC font"
<BR>
}; <BR>
<P>int main(void) <BR>{ <BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode; <BR>
int style, midx, midy; <BR> int size = 1; <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> settextjustify(CENTER_TEXT, CENTER_TEXT); <BR>
<P> /* loop through the available text styles */
<BR> for (style=DEFAULT_FONT; style<=GOTHIC_FONT; style++)
<BR> { <BR> cleardevice();
<BR> if (style == TRIPLEX_FONT)
<BR> size = 4; <BR>
<P> /* select the text style */
<BR> settextstyle(style, HORIZ_DIR, size);
<BR>
<P> /* output a message */
<BR> outtextxy(midx, midy, fname[style]);
<BR> getch(); <BR> } <BR>
<P> /* clean up */ <BR> closegraph();
<BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: settime <BR>功 能: 设置系统时间 <BR>用 法: void settime(struct
time *timep); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <dos.h> <BR>
<P>int main(void) <BR>{ <BR> struct time t; <BR>
<P> gettime(&t); <BR> printf("The current
minute is: %d\n", t.ti_min); <BR> printf("The current hour is:
%d\n", t.ti_hour); <BR> printf("The current hundredth of a
second is: %d\n", t.ti_hund); <BR> printf("The current second
is: %d\n", t.ti_sec); <BR>
<P> /* Add one to the minutes struct element and then call
settime */ <BR> t.ti_min++; <BR>
settime(&t); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: setusercharsize <BR>功 能: 为矢量字体改变字符宽度和高度 <BR>用 法: void
far setusercharsize(int multx, int dirx, int multy, int diry); <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 autodetection */
<BR> int gdriver = DETECT, gmode, errorcode; <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> /* select a text style */ <BR>
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); <BR>
<P> /* move to the text starting position */ <BR>
moveto(0, getmaxy() / 2); <BR>
<P> /* output some normal text */ <BR>
outtext("Norm "); <BR>
<P> /* make the text 1/3 the normal width */ <BR>
setusercharsize(1, 3, 1, 1); <BR> outtext("Short "); <BR>
<P> /* make the text 3 times normal width */ <BR>
setusercharsize(3, 1, 1, 1); <BR> outtext("Wide"); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR>
<P>函数名: setvbuf <BR>功 能: 把缓冲区与流相关 <BR>用 法: int setvbuf(FILE
*stream, char *buf, int type, unsigned size); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> FILE *input, *output;
<BR> char bufr[512]; <BR>
<P> input = fopen("file.in", "r+b"); <BR> output =
fopen("file.out", "w"); <BR>
<P> /* set up input stream for minimal disk access,
<BR> using our own character buffer */
<BR> if (setvbuf(input, bufr, _IOFBF, 512) != 0)
<BR> printf("failed to set up buffer for
input file\n"); <BR> else <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -