📄 fs.htm
字号:
<p> /* clean up */ <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: setblock <br>
功 能: 修改先前已分配的DOS存储段大小 <br>
用 法: int setblock(int seg, int newsize); <br>
程序例: </p>
<p>#include <dos.h> <br>
#include <alloc.h> <br>
#include <stdio.h> <br>
#include <stdlib.h> </p>
<p>int main(void) <br>
{ <br>
unsigned int size, segp; <br>
int stat; </p>
<p> size = 64; /* (64 x 16) = 1024 bytes */ <br>
stat = allocmem(size, &segp); <br>
if (stat == -1) <br>
printf("Allocated memory at
segment: %X\n", segp); <br>
else <br>
{ <br>
printf("Failed: maximum
number of paragraphs available is %d\n", <br>
stat); <br>
exit(1); <br>
} </p>
<p> stat = setblock(segp, size * 2); <br>
if (stat == -1) <br>
printf("Expanded memory block
at segment: %X\n", segp); <br>
else <br>
printf("Failed: maximum
number of paragraphs available is %d\n", <br>
stat); </p>
<p> freemem(segp); </p>
<p> return 0; <br>
} <br>
<br>
</p>
<p>函数名: setbuf <br>
功 能: 把缓冲区与流相联 <br>
用 法: void setbuf(FILE *steam, char *buf); <br>
程序例: </p>
<p>#include <stdio.h> </p>
<p>/* BUFSIZ is defined in stdio.h */ <br>
char outbuf[BUFSIZ]; </p>
<p>int main(void) <br>
{ <br>
/* attach a buffer to the standard output stream */ <br>
setbuf(stdout, outbuf); </p>
<p> /* put some characters into the buffer */ <br>
puts("This is a test of buffered
output.\n\n"); <br>
puts("This output will go into outbuf\n");
<br>
puts("and won't appear until the
buffer\n"); <br>
puts("fills up or we flush the
stream.\n"); </p>
<p> /* flush the output buffer */ <br>
fflush(stdout); </p>
<p> return 0; <br>
} <br>
<br>
</p>
<p>函数名: setcbrk <br>
功 能: 设置Control-break <br>
用 法: int setcbrk(int value); <br>
程序例: </p>
<p>#include <dos.h> <br>
#include <conio.h> <br>
#include <stdio.h> </p>
<p>int main(void) <br>
{ <br>
int break_flag; </p>
<p> printf("Enter 0 to turn control break
off\n"); <br>
printf("Enter 1 to turn control break
on\n"); </p>
<p> break_flag = getch() - 0; </p>
<p> setcbrk(break_flag); </p>
<p> if (getcbrk()) <br>
printf("Cntrl-brk flag is
on\n"); <br>
else <br>
printf("Cntrl-brk flag is
off\n"); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: setcolor <br>
功 能: 设置当前画线颜色 <br>
用 法: void far setcolor(int color); <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>
/* select a driver and mode that supports */ <br>
/* multiple drawing colors.
*/ <br>
int gdriver = EGA, gmode = EGAHI, errorcode; <br>
int color, maxcolor, x, y; <br>
char msg[80]; </p>
<p> /* initialize graphics and local variables */ <br>
initgraph(&gdriver, &gmode, ""); </p>
<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>
} </p>
<p> /* maximum color index supported */ <br>
maxcolor = getmaxcolor(); </p>
<p> /* for centering text messages */ <br>
settextjustify(CENTER_TEXT, CENTER_TEXT); <br>
x = getmaxx() / 2; <br>
y = getmaxy() / 2; </p>
<p> /* loop through the available colors */ <br>
for (color=1; color<=maxcolor; color++) <br>
{ <br>
/* clear the screen */ <br>
cleardevice(); </p>
<p> /* select a new background
color */ <br>
setcolor(color); </p>
<p> /* output a messsage */ <br>
sprintf(msg, "Color:
%d", color); <br>
outtextxy(x, y, msg); <br>
getch(); <br>
} </p>
<p> /* clean up */ <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: setdate <br>
功 能: 设置DOS日期 <br>
用 法: void setdate(struct date *dateblk); <br>
程序例: </p>
<p>#include <stdio.h> <br>
#include <process.h> <br>
#include <dos.h> </p>
<p>int main(void) <br>
{ <br>
struct date reset; <br>
struct date save_date; </p>
<p> getdate(&save_date); <br>
printf("Original date:\n"); <br>
system("date"); </p>
<p> reset.da_year = 2001; <br>
reset.da_day = 1; <br>
reset.da_mon = 1; <br>
setdate(&reset); </p>
<p> printf("Date after setting:\n"); <br>
system("date"); </p>
<p> setdate(&save_date); <br>
printf("Back to original date:\n"); <br>
system("date"); </p>
<p> return 0; <br>
} <br>
<br>
</p>
<p>函数名: setdisk <br>
功 能: 设置当前磁盘驱动器 <br>
用 法: int setdisk(int drive); <br>
程序例: </p>
<p>#include <stdio.h> <br>
#include <dir.h> </p>
<p>int main(void) <br>
{ <br>
int save, disk, disks; </p>
<p> /* save original drive */ <br>
save = getdisk(); </p>
<p> /* print number of logic drives */ <br>
disks = setdisk(save); <br>
printf("%d logical drives on the
system\n\n", disks); </p>
<p> /* print the drive letters available */ <br>
printf("Available drives:\n"); <br>
for (disk = 0;disk < 26;++disk) <br>
{ <br>
setdisk(disk); <br>
if (disk == getdisk()) <br>
printf("%c:
drive is available\n", disk + 'a'); <br>
} <br>
setdisk(save); </p>
<p> return 0; <br>
} <br>
<br>
</p>
<p>函数名: setdta <br>
功 能: 设置磁盘传输区地址 <br>
用 法: void setdta(char far *dta); <br>
程序例: </p>
<p>#include <process.h> <br>
#include <string.h> <br>
#include <stdio.h> <br>
#include <dos.h> </p>
<p>int main(void) <br>
{ <br>
char line[80], far *save_dta; <br>
char buffer[256] = "SETDTA test!"; <br>
struct fcb blk; <br>
int result; </p>
<p> /* get new file name from user */ <br>
printf("Enter a file name to create:"); <br>
gets(line); </p>
<p> /* parse the new file name to the dta */ <br>
parsfnm(line, &blk, 1); <br>
printf("%d %s\n", blk.fcb_drive,
blk.fcb_name); </p>
<p> /* request DOS services to create file */ <br>
if (bdosptr(0x16, &blk, 0) == -1) <br>
{ <br>
perror("Error creating
file"); <br>
exit(1); <br>
} </p>
<p> /* save old dta and set new dta */ <br>
save_dta = getdta(); <br>
setdta(buffer); </p>
<p> /* write new records */ <br>
blk.fcb_recsize = 256; <br>
blk.fcb_random = 0L; <br>
result = randbwr(&blk, 1); <br>
printf("result = %d\n", result); </p>
<p> if (!result) <br>
printf("Write OK\n"); <br>
else <br>
{ <br>
perror("Disk error"); <br>
exit(1); <br>
} </p>
<p> /* request DOS services to close the file */ <br>
if (bdosptr(0x10, &blk, 0) == -1) <br>
{ <br>
perror("Error closing
file"); <br>
exit(1); <br>
} </p>
<p> /* reset the old dta */ <br>
setdta(save_dta); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: setfillpattern <br>
功 能: 选择用户定义的填充模式 <br>
用 法: void far setfillpattern(char far *upattern, int
color); <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 maxx, maxy; </p>
<p> /* a user defined fill pattern */ <br>
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24,
0x24, 0x07, 0x00}; </p>
<p> /* initialize graphics and local variables */ <br>
initgraph(&gdriver, &gmode, ""); </p>
<p> /* read result of initialization */ <br>
errorcode = graphresult(); <br>
if (errorcode != grOk) /* an error occurred */
<br>
{ <br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -