📄 王大刚--c语言编程宝典--4_ 变量.htm
字号:
<P> /* Looks for non-existent file */ <BR> p
= searchpath("NOTEXIST.FIL"); <BR> printf("Search for
NOTEXIST.FIL : %s\n", p); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: sector <BR>功 能: 画并填充椭圆扇区 <BR>用 法: void far sector(int
x, int y, int stangle, int endangle); <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, i; <BR> int stangle = 45, endangle = 135;
<BR> int xrad = 100, yrad = 50; <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 the fill patterns */ <BR> for
(i=EMPTY_FILL; i<USER_FILL; i++) <BR> {
<BR> /* set the fill style */
<BR> setfillstyle(i, getmaxcolor()); <BR>
<P> /* draw the sector slice */
<BR> sector(midx, midy, stangle, endangle,
xrad, yrad); <BR>
<P> getch(); <BR> } <BR>
<P> /* clean up */ <BR> closegraph();
<BR> return 0; <BR>} <BR> <BR>
<P>函数名: segread <BR>功 能: 读段寄存器值 <BR>用 法: void segread(struct
SREGS *segtbl); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <dos.h> <BR>
<P>int main(void) <BR>{ <BR> struct SREGS segs; <BR>
<P> segread(&segs); <BR> printf("Current
segment register settings\n\n"); <BR> printf("CS:
%X DS: %X\n", segs.cs, segs.ds); <BR> printf("ES:
%X SS: %X\n", segs.es, segs.ss); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: setactivepage <BR>功 能: 设置图形输出活动页 <BR>用 法: void far
setactivepage(int pagenum); <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> /* select a driver and mode that
supports */ <BR> /* multiple
pages.
*/ <BR> int gdriver = EGA, gmode = EGAHI, errorcode;
<BR> int x, y, ht; <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> x = getmaxx() / 2; <BR> y = getmaxy() / 2;
<BR> ht = textheight("W"); <BR>
<P> /* select the off screen page for drawing */
<BR> setactivepage(1); <BR>
<P> /* draw a line on page #1 */ <BR> line(0, 0,
getmaxx(), getmaxy()); <BR>
<P> /* output a message on page #1 */ <BR>
settextjustify(CENTER_TEXT, CENTER_TEXT); <BR> outtextxy(x, y,
"This is page #1:"); <BR> outtextxy(x, y+ht, "Press any key to
halt:"); <BR>
<P> /* select drawing to page #0 */ <BR>
setactivepage(0); <BR>
<P> /* output a message on page #0 */ <BR>
outtextxy(x, y, "This is page #0."); <BR> outtextxy(x, y+ht,
"Press any key to view page #1:"); <BR> getch(); <BR>
<P> /* select page #1 as the visible page */ <BR>
setvisualpage(1); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: setallpallette <BR>功 能: 按指定方式改变所有的调色板颜色 <BR>用 法: void
far setallpallette(struct palette, far *pallette); <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>
struct palettetype pal; <BR> int color, maxcolor, ht;
<BR> int y = 10; <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> maxcolor = getmaxcolor(); <BR> ht = 2 *
textheight("W"); <BR>
<P> /* grab a copy of the palette */ <BR>
getpalette(&pal); <BR>
<P> /* display the default palette colors */ <BR>
for (color=1; color<=maxcolor; color++) <BR> {
<BR> setcolor(color);
<BR> sprintf(msg, "Color: %d", color);
<BR> outtextxy(1, y, msg);
<BR> y += ht; <BR> } <BR>
<P> /* wait for a key */ <BR> getch(); <BR>
<P> /* black out the colors one by one */ <BR> for
(color=1; color<=maxcolor; color++) <BR> {
<BR> setpalette(color, BLACK);
<BR> getch(); <BR> } <BR>
<P> /* restore the palette colors */ <BR>
setallpalette(&pal); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: setaspectratio <BR>功 能: 设置图形纵横比 <BR>用 法: void far
setaspectratio(int xasp, int yasp); <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 xasp, yasp, 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> setcolor(getmaxcolor()); <BR>
<P> /* get current aspect ratio settings */ <BR>
getaspectratio(&xasp, &yasp); <BR>
<P> /* draw normal circle */ <BR> circle(midx,
midy, 100); <BR> getch(); <BR>
<P> /* claer the screen */ <BR> cleardevice();
<BR>
<P> /* adjust the aspect for a wide circle */ <BR>
setaspectratio(xasp/2, yasp); <BR> circle(midx, midy, 100);
<BR> getch(); <BR>
<P> /* adjust the aspect for a narrow circle */
<BR> cleardevice(); <BR> setaspectratio(xasp,
yasp/2); <BR> circle(midx, midy, 100); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: setbkcolor <BR>功 能: 用调色板设置当前背景颜色 <BR>用 法: void far
setbkcolor(int c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -