C语言库函数S类字母2.docx
《C语言库函数S类字母2.docx》由会员分享,可在线阅读,更多相关《C语言库函数S类字母2.docx(25页珍藏版)》请在冰豆网上搜索。
C语言库函数S类字母2
C语言库函数(S类字母)-2
本文出自:
作者:
(2001-10-2608:
00:
01)
函数名:
setjmp
功 能:
非局部转移
用 法:
int setjmp(jmp_buf env);
程序例:
#include
#include
#include
void subroutine(void);
jmp_buf jumper;
int main(void)
{
int value;
value = setjmp(jumper);
if (value !
= 0)
{
printf("Longjmp with value %d\n", value);
exit(value);
}
printf("About to call subroutine ... \n");
subroutine();
return 0;
}
void subroutine(void)
{
longjmp(jumper,1);
}
函数名:
setlinestyle
功 能:
设置当前画线宽度和类型
用 法:
void far setlinestyle(int linestype, unsigned upattern);
程序例:
#include
#include
#include
#include
#include
/* the names of the line styles supported */
char *lname[] = {
"SOLID_LINE",
"DOTTED_LINE",
"CENTER_LINE",
"DASHED_LINE",
"USERBIT_LINE"
};
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int style, midx, midy, userpat;
char stylestr[40];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode !
= grOk) /* an error occurred */
{
printf("Graphics error:
%s\n", grapherrormsg(errorcode));
printf("Press any key to halt:
");
getch();
exit
(1); /* terminate with an error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
/* a user defined line pattern */
/* binary:
"0000000000000001" */
userpat = 1;
for (style=SOLID_LINE; style<=USERBIT_LINE; style++)
{
/* select the line style */
setlinestyle(style, userpat, 1);
/* convert style into a string */
strcpy(stylestr, lname[style]);
/* draw a line */
line(0, 0, midx-10, midy);
/* draw a rectangle */
rectangle(0, 0, getmaxx(), getmaxy());
/* output a message */
outtextxy(midx, midy, stylestr);
/* wait for a key */
getch();
cleardevice();
}
/* clean up */
closegraph();
return 0;
}
函数名:
setmem
功 能:
存值到存储区
用 法:
void setmem(void *addr, int len, char value);
程序例:
#include
#include
#include
int main(void)
{
char *dest;
dest = calloc(21, sizeof(char));
setmem(dest, 20, 'c');
printf("%s\n", dest);
return 0;
}
函数名:
setmode
功 能:
设置打开文件方式
用 法:
int setmode(int handle, unsigned mode);
程序例:
#include
#include
#include
int main(void)
{
int result;
result = setmode(fileno(stdprn), O_TEXT);
if (result == -1)
perror("Mode not available\n");
else
printf("Mode successfully switched\n");
return 0;
}
函数名:
setpalette
功 能:
改变调色板的颜色
用 法:
void far setpalette(int index, int actural_color);
程序例:
#include
#include
#include
#include
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int color, maxcolor, ht;
int y = 10;
char msg[80];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode !
= grOk) /* an error occurred */
{
printf("Graphics error:
%s\n", grapherrormsg(errorcode));
printf("Press any key to halt:
");
getch();
exit
(1); /* terminate with an error code */
}
maxcolor = getmaxcolor();
ht = 2 * textheight("W");
/* display the default colors */
for (color=1; color<=maxcolor; color++)
{
setcolor(color);
sprintf(msg, "Color:
%d", color);
outtextxy(1, y, msg);
y += ht;
}
/* wait for a key */
getch();
/* black out the colors one by one */
for (color=1; color<=maxcolor; color++)
{
setpalette(color, BLACK);
getch();
}
/* clean up */
closegraph();
return 0;
}
函数名:
setrgbpalette
功 能:
定义IBM8514图形卡的颜色
用 法:
void far setrgbpalette(int colornum, int red, int green, int blue);
程序例:
#include
#include
#include
#include
int main(void)
{
/* select a driver and mode that supports the use */
/* of the setrgbpalette function. */
int gdriver = VGA, gmode = VGAHI, errorcode;
struct palettetype pal;
int i, ht, y, xmax;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode !
= grOk) /* an error occurred */
{
printf("Graphics error:
%s\n", grapherrormsg(errorcode));
printf("Press any key to halt:
");
getch();
exit
(1); /* terminate with an error code */
}
/* grab a copy of the palette */
getpalette(&pal);
/* create gray scale */
for (i=0; i setrgbpalette(pal.colors[i], i*4, i*4, i*4);
/* display the gray scale */
ht = getmaxy() / 16;
xmax = getmaxx();
y = 0;
for (i=0; i {
setfillstyle(SOLID_FILL, i);
bar(0, y, xmax, y+ht);
y += ht;
}
/* clean up */
getch();
closegraph();
return 0;
}
函数名:
settextjustify
功 能:
为图形函数设置文本的对齐方式
用 法:
void far settextjustify(int horiz, int vert);
程序例:
#include
#include
#include
#include
/* function prototype */
void xat(int x, int y);
/* horizontal text justification settings */
char *hjust[] = { "LEFT_TEXT",
"CENTER_TEXT",
"RIGHT_TEXT"
};
/* vertical text justification settings */
char *vjust[] = { "LEFT_TEXT",
"CENTER_TEXT",
"RIGHT_TEXT"
};
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy, hj, vj;
char msg[80];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode !
= grOk) /* an error occurred */
{
printf("Graphics error:
%s\n", grapherrormsg(errorcode));
printf("Press any key to halt:
");
getch();
exit
(1); /* terminate with an error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
/* loop through text justifications */
for (hj=LEFT_TEXT; hj<=RIGHT_TEXT; hj++)
for (vj=LEFT_TEXT; vj<=RIGHT_TEXT; vj++)
{
cleardevice();
/* set the text justification */
settextjustify(hj, vj);
/* create a message string */
sprintf(msg, "%s %s", hjust[hj], vjust[vj]);
/* create cross hairs on the screen */
xat(midx, midy);
/* output the message */
outtextxy(midx, midy, msg);
getch();
}
/* clean up */
closegraph();
return 0;
}
/* draw an "x" at (x, y) */
void xat(int x, int y)
{
line(x-4, y, x+4, y);
line(x, y-4, x, y+4);
}
函数名:
settextstyle
功 能:
为图形输出设置当前的文本属性
用 法:
void far settextstyle (int font, int direction, char size);
程序例:
#include
#include
#include
#include
/* the names of the text styles supported */
char *fname[] = { "DEFAULT font",
"TRIPLEX font",
"SMALL font",
"SANS SERIF font",
"GOTHIC font"
};
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int style, midx, midy;
int size = 1;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode !
= grOk) /* an error occurred */
{
printf("Graphics error:
%s\n", grapherrormsg(errorcode));
printf("Press any key to halt:
");
getch();
exit
(1); /* terminate with an error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
settextjustify(CENTER_TEXT, CENTER_TEXT);
/* loop through the available text styles */
for (style=DEFAULT_FONT; style<=GOTHIC_FONT; style++)
{
cleardevice();
if (style == TRIPLEX_FONT)
size = 4;
/* select the text style */
settextstyle(style, HORIZ_DIR, size);
/* output a message */
outtextxy(midx, midy, fname[style]);
getch();
}
/* clean up */
closegraph();
return 0;
}
函数名:
settextstyle
功 能:
为图形输出设置当前的文本属性
用 法:
void far settextstyle (int font, int direction, char size);
程序例:
#include
#include
#include
#include
/* the names of the text styles supported */
char *fname[] = { "DEFAULT font",
"TRIPLEX font",
"SMALL font",
"SANS SERIF font",
"GOTHIC font"
};
int main(vo