⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 王大刚--c语言编程宝典--s.htm

📁 初学者的良师益友。其中包括C的全部教程。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<!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>功&nbsp; 能: 改变数据段空间位置 <BR>用&nbsp; 法: char *sbrk(int incr); 
      <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;alloc.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; printf("Changing allocation with 
      sbrk()\n"); <BR>&nbsp;&nbsp; printf("Before sbrk() call: %lu bytes 
      free\n", <BR>&nbsp;&nbsp; (unsigned long) coreleft()); <BR>&nbsp;&nbsp; 
      sbrk(1000); <BR>&nbsp;&nbsp; printf(" After sbrk() call: %lu bytes 
      free\n", <BR>&nbsp;&nbsp; (unsigned long) coreleft()); <BR>&nbsp;&nbsp; 
      return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: scanf <BR>功&nbsp; 能: 执行格式化输入 <BR>用&nbsp; 法: int scanf(char 
      *format[,argument,...]); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char label[20]; <BR>&nbsp;&nbsp; 
      char name[20]; <BR>&nbsp;&nbsp; int entries = 0; <BR>&nbsp;&nbsp; int 
      loop, age; <BR>&nbsp;&nbsp; double salary; <BR>
      <P>&nbsp;&nbsp; struct Entry_struct <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char&nbsp; name[20]; 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp; age; 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float salary; <BR>&nbsp;&nbsp; } 
      entry[20]; <BR>
      <P>/* Input a label as a string of characters restricting to 20 characters 
      */ <BR>&nbsp;&nbsp; printf("\n\nPlease enter a label for the chart: "); 
      <BR>&nbsp;&nbsp; scanf("%20s", label); <BR>&nbsp;&nbsp; 
      fflush(stdin);&nbsp; /* flush the input stream in case of bad input */ 
<BR>
      <P>/* Input number of entries as an integer */ <BR>&nbsp;&nbsp; 
      printf("How many entries will there be? (less than 20) "); 
      <BR>&nbsp;&nbsp; scanf("%d", &amp;entries); <BR>&nbsp;&nbsp; 
      fflush(stdin);&nbsp;&nbsp; /* flush the input stream in case of bad input 
      */ <BR>
      <P>/* input a name restricting input to only letters upper or lower case 
      */ <BR>&nbsp;&nbsp; for (loop=0;loop&lt;entries;++loop) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Entry %d\n", loop); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("&nbsp; Name&nbsp;&nbsp; : "); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf("%[A-Za-z]", entry[loop].name); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fflush(stdin);&nbsp; /* flush the input 
      stream in case of bad input */ <BR>
      <P>/* input an age as an integer */ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("&nbsp; Age&nbsp;&nbsp;&nbsp; : "); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf("%d", &amp;entry[loop].age); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fflush(stdin);&nbsp; /* flush the input 
      stream in case of bad input */ <BR>
      <P>/* input a salary as a float */ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("&nbsp; Salary : "); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf("%f", 
      &amp;entry[loop].salary); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      fflush(stdin); /* flush the input stream in case of bad input */ 
      <BR>&nbsp;&nbsp; } <BR>
      <P>/* Input a name, age and salary as a string, integer, and double */ 
      <BR>&nbsp;&nbsp; printf("\nPlease enter your name, age and salary\n"); 
      <BR>&nbsp;&nbsp; scanf("%20s %d %lf", name, &amp;age, &amp;salary); 
      <BR>&nbsp; <BR>
      <P>/* Print out the data that was input */ <BR>&nbsp;&nbsp; 
      printf("\n\nTable %s\n",label); <BR>&nbsp;&nbsp; printf("Compiled by 
      %s&nbsp; age %d&nbsp; $%15.2lf\n", name, age, salary); <BR>&nbsp;&nbsp; 
      printf("-----------------------------------------------------\n"); 
      <BR>&nbsp;&nbsp; for (loop=0;loop&lt;entries;++loop) 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%4d | %-20s | %5d | %15.2lf\n", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; loop + 1, <BR>&nbsp; 
      entry[loop].name, <BR>&nbsp; entry[loop].age, 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entry[loop].salary); 
      <BR>&nbsp;&nbsp; 
      printf("-----------------------------------------------------\n"); 
      <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: searchpath <BR>功&nbsp; 能: 搜索DOS路径 <BR>用&nbsp; 法: char 
      *searchpath(char *filename); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;dir.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char *p; <BR>
      <P>&nbsp;&nbsp; /* Looks for TLINK and returns a pointer 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to the path&nbsp; */ <BR>&nbsp;&nbsp; p 
      = searchpath("TLINK.EXE"); <BR>&nbsp;&nbsp; printf("Search for TLINK.EXE : 
      %s\n", p); <BR>
      <P>&nbsp;&nbsp; /* Looks for non-existent file&nbsp; */ <BR>&nbsp;&nbsp; p 
      = searchpath("NOTEXIST.FIL"); <BR>&nbsp;&nbsp; printf("Search for 
      NOTEXIST.FIL : %s\n", p); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: sector <BR>功&nbsp; 能: 画并填充椭圆扇区 <BR>用&nbsp; 法: void far sector(int 
      x, int y, int stangle, int endangle); <BR>程序例: <BR>
      <P>#include &lt;graphics.h&gt; <BR>#include &lt;stdlib.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; /* request auto detection */ 
      <BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <BR>&nbsp;&nbsp; 
      int midx, midy, i; <BR>&nbsp;&nbsp; int stangle = 45, endangle = 135; 
      <BR>&nbsp;&nbsp; int xrad = 100, yrad = 50; <BR>
      <P>&nbsp;&nbsp; /* initialize graphics and local variables */ 
      <BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, ""); <BR>
      <P>&nbsp;&nbsp; /* read result of initialization */ <BR>&nbsp;&nbsp; 
      errorcode = graphresult(); <BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; 
      /* an error occurred */ <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", 
      grapherrormsg(errorcode)); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("Press any key to halt:"); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      getch(); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with an 
      error code */ <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; midx = getmaxx() / 2; <BR>&nbsp;&nbsp; midy = getmaxy() / 
      2; <BR>
      <P>&nbsp;&nbsp; /* loop through the fill patterns */ <BR>&nbsp;&nbsp; for 
      (i=EMPTY_FILL; i&lt;USER_FILL; i++) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* set the fill style */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setfillstyle(i, getmaxcolor()); <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* draw the sector slice */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sector(midx, midy, stangle, endangle, 
      xrad, yrad); <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* clean up */ <BR>&nbsp;&nbsp; closegraph(); 
      <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>
      <P>函数名: segread <BR>功&nbsp; 能: 读段寄存器值 <BR>用&nbsp; 法: void segread(struct 
      SREGS *segtbl); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;dos.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; struct SREGS segs; <BR>
      <P>&nbsp;&nbsp; segread(&amp;segs); <BR>&nbsp;&nbsp; printf("Current 
      segment register settings\n\n"); <BR>&nbsp;&nbsp; printf("CS: 
      %X&nbsp;&nbsp; DS: %X\n", segs.cs, segs.ds); <BR>&nbsp;&nbsp; printf("ES: 
      %X&nbsp;&nbsp; SS: %X\n", segs.es, segs.ss); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: setactivepage <BR>功&nbsp; 能: 设置图形输出活动页 <BR>用&nbsp; 法: void far 
      setactivepage(int pagenum); <BR>程序例: <BR>
      <P>#include &lt;graphics.h&gt; <BR>#include &lt;stdlib.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; /* select a driver and mode that 
      supports */ <BR>&nbsp;&nbsp; /* multiple 
      pages.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      */ <BR>&nbsp;&nbsp; int gdriver = EGA, gmode = EGAHI, errorcode; 
      <BR>&nbsp;&nbsp; int x, y, ht; <BR>
      <P>&nbsp;&nbsp; /* initialize graphics and local variables */ 
      <BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, ""); <BR>
      <P>&nbsp;&nbsp; /* read result of initialization */ <BR>&nbsp;&nbsp; 
      errorcode = graphresult(); <BR>&nbsp;&nbsp; if (errorcode != grOk)&nbsp; 
      /* an error occurred */ <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", 
      grapherrormsg(errorcode)); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("Press any key to halt:"); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      getch(); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with an 
      error code */ <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; x = getmaxx() / 2; <BR>&nbsp;&nbsp; y = getmaxy() / 2; 
      <BR>&nbsp;&nbsp; ht = textheight("W"); <BR>
      <P>&nbsp;&nbsp; /*&nbsp; select the off screen page for drawing */ 
      <BR>&nbsp;&nbsp; setactivepage(1); <BR>
      <P>&nbsp;&nbsp; /* draw a line on page #1 */ <BR>&nbsp;&nbsp; line(0, 0, 
      getmaxx(), getmaxy()); <BR>
      <P>&nbsp;&nbsp; /* output a message on page #1 */ <BR>&nbsp;&nbsp; 
      settextjustify(CENTER_TEXT, CENTER_TEXT); <BR>&nbsp;&nbsp; outtextxy(x, y, 
      "This is page #1:"); <BR>&nbsp;&nbsp; outtextxy(x, y+ht, "Press any key to 
      halt:"); <BR>
      <P>&nbsp;&nbsp; /* select drawing to page #0 */ <BR>&nbsp;&nbsp; 
      setactivepage(0); <BR>
      <P>&nbsp;&nbsp; /* output a message&nbsp; on page #0 */ <BR>&nbsp;&nbsp; 
      outtextxy(x, y, "This is page #0."); <BR>&nbsp;&nbsp; outtextxy(x, y+ht, 
      "Press any key to view page #1:"); <BR>&nbsp;&nbsp; getch(); <BR>
      <P>&nbsp;&nbsp; /* select page #1 as the visible page */ <BR>&nbsp;&nbsp; 
      setvisualpage(1); <BR>
      <P>&nbsp;&nbsp; /* clean up */ <BR>&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; 
      closegraph(); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: setallpallette <BR>功&nbsp; 能: 按指定方式改变所有的调色板颜色 <BR>用&nbsp; 法: void 
      far setallpallette(struct palette, far *pallette); <BR>程序例: <BR>
      <P>#include &lt;graphics.h&gt; <BR>#include &lt;stdlib.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -