📄 fs.htm
字号:
</p>
<p>函数名: setaspectratio <br>
功 能: 设置图形纵横比 <br>
用 法: void far setaspectratio(int xasp, int
yasp); <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 xasp, yasp, midx, midy; </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> midx = getmaxx() / 2; <br>
midy = getmaxy() / 2; <br>
setcolor(getmaxcolor()); </p>
<p> /* get current aspect ratio settings */ <br>
getaspectratio(&xasp, &yasp); </p>
<p> /* draw normal circle */ <br>
circle(midx, midy, 100); <br>
getch(); </p>
<p> /* claer the screen */ <br>
cleardevice(); </p>
<p> /* adjust the aspect for a wide circle */
<br>
setaspectratio(xasp/2, yasp); <br>
circle(midx, midy, 100); <br>
getch(); </p>
<p> /* adjust the aspect for a narrow circle
*/ <br>
cleardevice(); <br>
setaspectratio(xasp, yasp/2); <br>
circle(midx, midy, 100); </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: setbkcolor <br>
功 能: 用调色板设置当前背景颜色 <br>
用 法: void far setbkcolor(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 background colors.
*/ <br>
int gdriver = EGA, gmode = EGAHI, errorcode;
<br>
int bkcol, 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 (bkcol=0; bkcol<=maxcolor; bkcol++) <br>
{ <br>
/* clear the screen */ <br>
cleardevice(); </p>
<p> /* select a new
background color */ <br>
setbkcolor(bkcol); </p>
<p> /* output a messsage */
<br>
if (bkcol == WHITE) <br>
setcolor(EGA_BLUE); <br>
sprintf(msg,
"Background color: %d", bkcol); <br>
outtextxy(x, y, msg); <br>
getch(); <br>
} </p>
<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>
} </p>
</td>
</tr>
</table>
</center></div><div align="center"><center>
<table border="0" cellspacing="1" width="640">
<tr>
<td class="p9" height="60"> <script>document.write("<p><a href=\"http://view.gznet.com/cgi-bin/rl_views.cgi?UID=10013421\" target=sxrl>");
document.write("<img src=\"http://refer.gznet.com/cgi-bin/rl_refer2.cgi?UID=10013421&refer="+escape(top.document.referrer)+"\" width=1 height=1 border=0 alt=\" \">");
document.write("</a>");
</script></td>
</tr>
</table>
</center></div>
<p>函数名: sbrk <br>
功 能: 改变数据段空间位置 <br>
用 法: char *sbrk(int incr); <br>
程序例: </p>
<p>#include <stdio.h> <br>
#include <alloc.h> </p>
<p>int main(void) <br>
{ <br>
printf("Changing allocation with
sbrk()\n"); <br>
printf("Before sbrk() call: %lu bytes
free\n", <br>
(unsigned long) coreleft()); <br>
sbrk(1000); <br>
printf(" After sbrk() call: %lu bytes
free\n", <br>
(unsigned long) coreleft()); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: scanf <br>
功 能: 执行格式化输入 <br>
用 法: int scanf(char *format[,argument,...]); <br>
程序例: </p>
<p>#include <stdio.h> <br>
#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
char label[20]; <br>
char name[20]; <br>
int entries = 0; <br>
int loop, age; <br>
double salary; </p>
<p> struct Entry_struct <br>
{ <br>
char name[20]; <br>
int age; <br>
float salary; <br>
} entry[20]; </p>
<p>/* Input a label as a string of characters restricting to 20
characters */ <br>
printf("\n\nPlease enter a label for the chart:
"); <br>
scanf("%20s", label); <br>
fflush(stdin); /* flush the input stream in
case of bad input */ </p>
<p>/* Input number of entries as an integer */ <br>
printf("How many entries will there be? (less
than 20) "); <br>
scanf("%d", &entries); <br>
fflush(stdin); /* flush the input stream
in case of bad input */ </p>
<p>/* input a name restricting input to only letters upper or
lower case */ <br>
for (loop=0;loop<entries;++loop) <br>
{ <br>
printf("Entry %d\n",
loop); <br>
printf(" Name
: "); <br>
scanf("%[A-Za-z]",
entry[loop].name); <br>
fflush(stdin); /* flush the
input stream in case of bad input */ </p>
<p>/* input an age as an integer */ <br>
printf(" Age
: "); <br>
scanf("%d",
&entry[loop].age); <br>
fflush(stdin); /* flush the
input stream in case of bad input */ </p>
<p>/* input a salary as a float */ <br>
printf(" Salary :
"); <br>
scanf("%f",
&entry[loop].salary); <br>
fflush(stdin); /* flush the input
stream in case of bad input */ <br>
} </p>
<p>/* Input a name, age and salary as a string, integer, and
double */ <br>
printf("\nPlease enter your name, age and
salary\n"); <br>
scanf("%20s %d %lf", name, &age,
&salary); <br>
</p>
<p>/* Print out the data that was input */ <br>
printf("\n\nTable %s\n",label); <br>
printf("Compiled by %s age %d
$%15.2lf\n", name, age, salary); <br>
printf("-----------------------------------------------------\n");
<br>
for (loop=0;loop<entries;++loop) <br>
printf("%4d | %-20s | %5d |
%15.2lf\n", <br>
loop + 1, <br>
entry[loop].name, <br>
entry[loop].age, <br>
entry[loop].salary); <br>
printf("-----------------------------------------------------\n");
<br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: searchpath <br>
功 能: 搜索DOS路径 <br>
用 法: char *searchpath(char *filename); <br>
程序例: </p>
<p>#include <stdio.h> <br>
#include <dir.h> </p>
<p>int main(void) <br>
{ <br>
char *p; </p>
<p> /* Looks for TLINK and returns a pointer <br>
to the path */ <br>
p = searchpath("TLINK.EXE"); <br>
printf("Search for TLINK.EXE : %s\n", p); </p>
<p> /* Looks for non-existent file */ <br>
p = searchpath("NOTEXIST.FIL"); <br>
printf("Search for NOTEXIST.FIL : %s\n",
p); </p>
<p> return 0; <br>
} <br>
<br>
</p>
<p>函数名: sector <br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -