函数名: setdta
功 能: 设置磁盘传输区地址
用 法: void setdta(char far *dta);
程序例:
#include
#include
#include
#include
int main(void)
{
char line[80], far *save_dta;
char buffer[256] = "SETDTA test!";
struct fcb blk;
int result;
printf("Enter a file name to create:");
gets(line);
parsfnm(line, &blk, 1);
printf("%d %s\n", blk.fcb_drive, blk.fcb_name);
if (bdosptr(0x16, &blk, 0) == -1)
{
perror("Error creating file");
exit(1);
}
save_dta = getdta();
setdta(buffer);
blk.fcb_recsize = 256;
blk.fcb_random = 0L;
result = randbwr(&blk, 1);
printf("result = %d\n", result);
if (!result)
printf("Write OK\n");
else
{
perror("Disk error");
exit(1);
}
if (bdosptr(0x10, &blk, 0) == -1)
{
perror("Error closing file");
exit(1);
}
setdta(save_dta);
return 0;
}
函数名: setfillpattern
功 能: 选择用户定义的填充模式
用 法: void far setfillpattern(char far *upattern, int color);
程序例:
#include
#include
#include
#include
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy;
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07,
0x00};
initgraph(&gdriver, &gmode,
"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxx = getmaxx();
maxy = getmaxy();
setcolor(getmaxcolor());
setfillpattern(pattern, getmaxcolor());
bar(0, 0, maxx, maxy);
getch();
closegraph();
return 0;
}
函数名: setfillstyle
功 能: 设置填充模式和颜色
用 法: void far setfillstyle(int pattern, int color);
程序例:
#include
#include
#include
#include
#include
char *fname[] = { "EMPTY_FILL",
"SOLID_FILL",
"LINE_FILL",
"LTSLASH_FILL",
"SLASH_FILL",
"BKSLASH_FILL",
"LTBKSLASH_FILL",
"HATCH_FILL",
"XHATCH_FILL",
"INTERLEAVE_FILL",
"WIDE_DOT_FILL",
"CLOSE_DOT_FILL",
"USER_FILL"
};
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int style, midx, midy;
char stylestr[40];
initgraph(&gdriver, &gmode,
"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
for (style = EMPTY_FILL; style < USER_FILL;
style++)
{
setfillstyle(style, getmaxcolor());
strcpy(stylestr, fname[style]);
bar3d(0, 0, midx-10, midy, 0, 0);
outtextxy(midx, midy, stylestr);
getch();
cleardevice();
}
getch();
closegraph();
return 0;
}
函数名: setftime
功 能: 设置文件日期和时间
用 法: int setftime(int handle, struct ftime *ftimep);
程序例:
#include
#include
#include
#include
int main(void)
{
struct ftime filet;
FILE *fp;
if ((fp = fopen("TEST.$$$", "w")) == NULL)
{
perror("Error:");
exit(1);
}
fprintf(fp, "testing...\n");
filet.ft_tsec = 1;
filet.ft_min = 1;
filet.ft_hour = 1;
filet.ft_day = 1;
filet.ft_month = 1;
filet.ft_year = 21;
system("dir TEST.$$$");
setftime(fileno(fp), &filet);
fclose(fp);
system("dir TEST.$$$");
unlink("TEST.$$$");
return 0;
}
函数名: setgraphbufsize
功 能: 改变内部图形缓冲区的大小
用 法: unsigned far setgraphbufsize(unsigned bufsize);
程序例:
#include
#include
#include
#include
#define BUFSIZE 1000
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int x, y, oldsize;
char msg[80];
oldsize = setgraphbufsize(BUFSIZE);
initgraph(&gdriver, &gmode,
"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
x = getmaxx() / 2;
y = getmaxy() / 2;
sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(x, y, msg);
sprintf(msg, "Old graphics buffer size: %d", oldsize);
outtextxy(x, y+textheight("W"), msg);
getch();
closegraph();
return 0;
}
函数名: setgraphmode
功 能: 将系统设置成图形模式且清屏
用 法: void far setgraphmode(int mode);
程序例:
#include
#include
#include #include
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int x, y;
initgraph(&gdriver, &gmode,
"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
x = getmaxx() / 2;
y = getmaxy() / 2;
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(x, y, "Press any key to exit graphics:");
getch();
restorecrtmode();
printf("We're now in text mode.\n");
printf("Press any key to return to graphics mode:");
getch();
setgraphmode(getgraphmode());
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(x, y, "We're back in graphics mode.");
outtextxy(x, y+textheight("W"), "Press any key to halt:");
getch();
closegraph();
return 0;
}
函数名: 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
char *lname[] = {
"SOLID_LINE",
"DOTTED_LINE",
"CENTER_LINE",
"DASHED_LINE",
"USERBIT_LINE"
};
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int style, midx, midy, userpat;
char stylestr[40];
initgraph(&gdriver, &gmode,
"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
userpat = 1;
for (style=SOLID_LINE; style<=USERBIT_LINE;
style++)
{
setlinestyle(style, userpat, 1);
strcpy(stylestr, lname[style]);
line(0, 0, midx-10, midy);
rectangle(0, 0, getmaxx(), getmaxy());
outtextxy(midx, midy, stylestr);
getch();
cleardevice();
}
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)
{
int gdriver = DETECT, gmode, errorcode;
int color, maxcolor, ht;
int y = 10;
char msg[80];
initgraph(&gdriver, &gmode,
"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxcolor = getmaxcolor();
ht = 2 * textheight("W");
for (color=1; color<=maxcolor; color++)
{
setcolor(color);
sprintf(msg, "Color: %d", color);
outtextxy(1, y, msg);
y += ht;
}
getch();
for (color=1; color<=maxcolor; color++)
{
setpalette(color, BLACK);
getch();
}
closegraph();
return 0;
}
函数名: setrgbpalette
功 能: 定义IBM8514图形卡的颜色
用 法: void far setrgbpalette(int colornum, int red, int green, int
blue);
程序例:
#include
#include
#include
#include
int main(void)
{
int gdriver = VGA, gmode = VGAHI, errorcode;
struct palettetype pal;
int i, ht, y, xmax;
initgraph(&gdriver, &gmode,
"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
getpalette(&pal);
for (i=0; i
setrgbpalette(pal.colors[i], i*4, i*4, i*4);
ht = getmaxy() / 16;
xmax = getmaxx();
y = 0;
for (i=0; i
{
setfillstyle(SOLID_FILL, i);
bar(0, y, xmax, y+ht);
y += ht;
}
getch();
closegraph();
return 0;
}
函数名: settextjustify
功 能: 为图形函数设置文本的对齐方式
用 法: void far settextjustify(int horiz, int vert);
程序例:
#include
#include
#include
#include
void xat(int x, int y);
char *hjust[] = { "LEFT_TEXT",
"CENTER_TEXT",
"RIGHT_TEXT"
};
char *vjust[] = { "LEFT_TEXT",
"CENTER_TEXT",
"RIGHT_TEXT"
};
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int midx, midy, hj, vj;
char msg[80];
initgraph(&gdriver, &gmode,
"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
for (hj=LEFT_TEXT; hj<=RIGHT_TEXT; hj++)
for (vj=LEFT_TEXT; vj<=RIGHT_TEXT; vj++)
{
cleardevice();
settextjustify(hj, vj);
sprintf(msg, "%s %s", hjust[hj], vjust[vj]);
xat(midx, midy);
outtextxy(midx, midy, msg);
getch();
}
closegraph();
return 0;
}
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
char *fname[] = { "DEFAULT font",
"TRIPLEX font",
"SMALL font",
"SANS SERIF font",
"GOTHIC font"
};
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int style, midx, midy;
int size = 1;
initgraph(&gdriver, &gmode,
"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
settextjustify(CENTER_TEXT, CENTER_TEXT);
for (style=DEFAULT_FONT; style<=GOTHIC_FONT;
style++)
{
cleardevice();
if (style == TRIPLEX_FONT)
size = 4;
settextstyle(style, HORIZ_DIR, size);
outtextxy(midx, midy, fname[style]);
getch();
}
closegraph();
return 0;
}
函数名: settextstyle
功 能: 为图形输出设置当前的文本属性
用 法: void far settextstyle (int font, int direction, char
size);
程序例:
#include
#include
#include
#include
char *fname[] = { "DEFAULT font",
"TRIPLEX font",
"SMALL font",
"SANS SERIF font",
"GOTHIC font"
};
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int style, midx, midy;
int size = 1;
initgraph(&gdriver, &gmode,
"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
settextjustify(CENTER_TEXT, CENTER_TEXT);
for (style=DEFAULT_FONT; style<=GOTHIC_FONT;
style++)
{
cleardevice();
if (style == TRIPLEX_FONT)
size = 4;
settextstyle(style, HORIZ_DIR, size);
outtextxy(midx, midy, fname[style]);
getch();
}
closegraph();
return 0;
}
函数名: settime
功 能: 设置系统时间
用 法: void settime(struct time *timep);
程序例:
#include
#include
int main(void)
{
struct time t;
gettime(&t);
printf("The current minute is: %d\n", t.ti_min);
printf("The current hour is: %d\n", t.ti_hour);
printf("The current hundredth of a second is: %d\n",
t.ti_hund);
printf("The current second is: %d\n", t.ti_sec);
t.ti_min++;
settime(&t);
return 0;
}
函数名: setusercharsize
功 能: 为矢量字体改变字符宽度和高度
用 法: void far setusercharsize(int multx, int dirx, int multy, int
diry);
程序例:
#include
#include
#include
#include
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode,
"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4);
moveto(0, getmaxy() / 2);
outtext("Norm ");
setusercharsize(1, 3, 1, 1);
outtext("Short ");
setusercharsize(3, 1, 1, 1);
outtext("Wide");
getch();
closegraph();
return 0;
}
函数名: setvbuf
功 能: 把缓冲区与流相关
用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned
size);
程序例:
#include
int main(void)
{
FILE *input, *output;
char bufr[512];
input = fopen("file.in", "r+b");
output = fopen("file.out", "w");
if (setvbuf(input, bufr, _IOFBF, 512) != 0)
printf("failed to set up buffer for input file\n");
else
printf("buffer set up for input file\n");
if (setvbuf(output, NULL, _IOLBF, 132) != 0)
printf("failed to set up buffer for output file\n");
else
printf("buffer set up for output file\n");
fclose(input);
fclose(output);
return 0;
}
函数名: setvect
功 能: 设置中断矢量入口
用 法: void setvect(int intr_num, void interrupt(*isr)());
程序例:
#include
#include
#include
#define INTR 0X1C
void interrupt ( *oldhandler)(void);
int count=0;
void interrupt handler(void)
{
count++;
oldhandler();
}
int main(void)
{
oldhandler = getvect(INTR);
setvect(INTR, handler);
while (count < 20)
printf("count is %d\n",count);
setvect(INTR, oldhandler);
return 0;
}
函数名: setverify
功 能: 设置验证状态
用 法: void setverify(int value);
程序例:
#include
#include
#include
int main(void)
{
int verify_flag;
printf("Enter 0 to set verify flag off\n");
printf("Enter 1 to set verify flag on\n");
verify_flag = getch() - 0;
setverify(verify_flag);
if (getverify())
printf("DOS verify flag is on\n");
else
printf("DOS verify flag is off\n");
return 0;
}
函数名: setviewport
功 能: 为图形输出设置当前视口
用 法: void far setviewport(int left, int top, int right,
int bottom, int clipflag);
程序例:
#include
#include
#include
#include
#define CLIP_ON 1
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode,
"");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
setcolor(getmaxcolor());
outtextxy(0, 0, "*
viewport");
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON);
outtextxy(0, 0, "*
viewport");
getch();
closegraph();
return 0;
}