📄 王大刚--c语言编程宝典--s.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/036.htm -->
<HTML><HEAD><TITLE>王大刚-->C语言编程宝典-->S</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大刚 C语言编程宝典 S" name=keywords>
<META content="王大刚 - C语言编程宝典 - S" name=description>
<STYLE>#page {
LEFT: 0px; POSITION: absolute; TOP: 0px
}
.tt3 {
FONT: 9pt/12pt "宋体"
}
.tt2 {
FONT: 12pt/15pt "宋体"
}
A {
TEXT-DECORATION: none
}
A:hover {
COLOR: blue; TEXT-DECORATION: underline
}
</STYLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY text=#000000 vLink=#006699 aLink=#9900ff link=#006699 bgColor=#ffffff
leftMargin=3 topMargin=3 marginwidth="3" marginheight="3">
<TABLE cellSpacing=0 cellPadding=10 width="100%" border=0>
<TBODY>
<TR>
<TD class=tt3 vAlign=top width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/037.htm">后一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/035.htm">前一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/index.html">回目录</A><BR><A
href="http://www.hjflying.8u8.com/index.htm">回首页</A><BR></STRONG></TD>
<TD class=tt2 width="84%" bgColor=#f5f8f8>
<CENTER><B><FONT style="FONT-SIZE: 16.5pt" face=楷体_GB2312
color=#ff6666>S</FONT></B></CENTER>
<HR width="94%" color=#ee9b73 SIZE=1>
<P>函数名: sbrk <BR>功 能: 改变数据段空间位置 <BR>用 法: char *sbrk(int incr);
<BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <alloc.h> <BR>
<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> <BR>
<P>函数名: scanf <BR>功 能: 执行格式化输入 <BR>用 法: int scanf(char
*format[,argument,...]); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> char label[20]; <BR>
char name[20]; <BR> int entries = 0; <BR> int
loop, age; <BR> double salary; <BR>
<P> struct Entry_struct <BR> {
<BR> char name[20];
<BR> int age;
<BR> float salary; <BR> }
entry[20]; <BR>
<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 */
<BR>
<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
*/ <BR>
<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 */ <BR>
<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 */ <BR>
<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> } <BR>
<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> <BR>
<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> <BR>
<P>函数名: searchpath <BR>功 能: 搜索DOS路径 <BR>用 法: char
*searchpath(char *filename); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <dir.h> <BR>
<P>int main(void) <BR>{ <BR> char *p; <BR>
<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); <BR>
<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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -