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

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

📁 初学者的良师益友。其中包括C的全部教程。
💻 HTM
📖 第 1 页 / 共 2 页
字号:
      "******************************"; <BR>&nbsp; printf("destination prior to 
      memmove: %s\n", dest); <BR>&nbsp; memmove(dest, src, 26); <BR>&nbsp; 
      printf("destination after memmove:&nbsp;&nbsp;&nbsp; %s\n", dest); 
      <BR>&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: memset <BR>功&nbsp; 能: 设置s中的所有字节为ch, s数组的大小由n给定 <BR>用&nbsp; 法: void 
      *memset(void *s, char ch, unsigned n); <BR>程序例: <BR>
      <P>#include &lt;string.h&gt; <BR>#include &lt;stdio.h&gt; <BR>#include 
      &lt;mem.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char buffer[] = "Hello world\n"; 
      <BR>
      <P>&nbsp;&nbsp; printf("Buffer before memset: %s\n", buffer); 
      <BR>&nbsp;&nbsp; memset(buffer, '*', strlen(buffer) - 1); <BR>&nbsp;&nbsp; 
      printf("Buffer after memset:&nbsp; %s\n", buffer); <BR>&nbsp;&nbsp; return 
      0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: mkdir <BR>功&nbsp; 能: 建立一个目录 <BR>用&nbsp; 法: int mkdir(char 
      *pathname); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>#include 
      &lt;process.h&gt; <BR>#include &lt;dir.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp; int status; <BR>
      <P>&nbsp;&nbsp; clrscr(); <BR>&nbsp;&nbsp; status = mkdir("asdfjklm"); 
      <BR>&nbsp;&nbsp; (!status) ? (printf("Directory created\n")) : 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      (printf("Unable to create directory\n")); <BR>
      <P>&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; system("dir"); <BR>&nbsp;&nbsp; 
      getch(); <BR>
      <P>&nbsp;&nbsp; status = rmdir("asdfjklm"); <BR>&nbsp;&nbsp; (!status) ? 
      (printf("Directory deleted\n")) : <BR>&nbsp; (perror("Unable to delete 
      directory")); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: mktemp <BR>功&nbsp; 能: 建立唯一的文件名 <BR>用&nbsp; 法: char *mktemp(char 
      *template); <BR>程序例: <BR>
      <P>#include &lt;dir.h&gt; <BR>#include &lt;stdio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; /* fname defines the template for 
      the <BR>&nbsp;&nbsp;&nbsp;&nbsp; temporary file.&nbsp; */ <BR>
      <P>&nbsp;&nbsp; char *fname = "TXXXXXX", *ptr; <BR>
      <P>&nbsp;&nbsp; ptr = mktemp(fname); <BR>&nbsp;&nbsp; printf("%s\n",ptr); 
      <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: MK_FP <BR>功&nbsp; 能: 设置一个远指针 <BR>用&nbsp; 法: void far 
      *MK_FP(unsigned seg, unsigned off); <BR>程序例: <BR>
      <P>#include &lt;dos.h&gt; <BR>#include &lt;graphics.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; int gd, gm, i; <BR>&nbsp;&nbsp; 
      unsigned int far *screen; <BR>
      <P>&nbsp;&nbsp; detectgraph(&amp;gd, &amp;gm); <BR>&nbsp;&nbsp; if (gd == 
      HERCMONO) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; screen = MK_FP(0xB000, 
      0); <BR>&nbsp;&nbsp; else <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; screen 
      = MK_FP(0xB800, 0); <BR>&nbsp;&nbsp; for (i=0; i&lt;26; i++) 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; screen[i] = 0x0700 + ('a' + i); 
      <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: modf <BR>功&nbsp; 能: 把数分为指数和尾数 <BR>用&nbsp; 法: double modf(double 
      value, double *iptr); <BR>程序例: <BR>
      <P>#include &lt;math.h&gt; <BR>#include &lt;stdio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; double fraction, integer; 
      <BR>&nbsp;&nbsp; double number = 100000.567; <BR>
      <P>&nbsp;&nbsp; fraction = modf(number, &amp;integer); <BR>&nbsp;&nbsp; 
      printf("The whole and fractional parts of %lf are %lf and %lf\n", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; number, 
      integer, fraction); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; 
      <BR>
      <P>函数名: movedata <BR>功&nbsp; 能: 拷贝字节 <BR>用&nbsp; 法: void movedata(int 
      segsrc, int offsrc, int segdest, <BR>&nbsp; int offdest, unsigned 
      numbytes); <BR>程序例: <BR>
      <P>#include &lt;mem.h&gt; <BR>
      <P>#define MONO_BASE 0xB000 <BR>
      <P>/* saves the contents of the monochrome screen in buffer */ <BR>void 
      save_mono_screen(char near *buffer) <BR>{ <BR>&nbsp;&nbsp; 
      movedata(MONO_BASE, 0, _DS, (unsigned)buffer, 80*25*2); <BR>} <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char buf[80*25*2]; 
      <BR>&nbsp;&nbsp; save_mono_screen(buf); <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: moverel <BR>功&nbsp; 能: 将当前位置(CP)移动一相对距离 <BR>用&nbsp; 法: void far 
      moverel(int dx, int dy); <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; 
      char msg[80]; <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; /* move the C.P. to location (20, 30) */ <BR>&nbsp;&nbsp; 
      moveto(20, 30); <BR>
      <P>&nbsp;&nbsp; /* plot a pixel at the C.P. */ <BR>&nbsp;&nbsp; 
      putpixel(getx(), gety(), getmaxcolor()); <BR>
      <P>&nbsp;&nbsp; /* create and output a message at (20, 30) */ 
      <BR>&nbsp;&nbsp; sprintf(msg, " (%d, %d)", getx(), gety()); 
      <BR>&nbsp;&nbsp; outtextxy(20, 30, msg); <BR>
      <P>&nbsp;&nbsp; /* move to a point a relative distance */ <BR>&nbsp;&nbsp; 
      /* away from the current value of C.P. */ <BR>&nbsp;&nbsp; moverel(100, 
      100); <BR>
      <P>&nbsp;&nbsp; /* plot a pixel at the C.P. */ <BR>&nbsp;&nbsp; 
      putpixel(getx(), gety(), getmaxcolor()); <BR>
      <P>&nbsp;&nbsp; /* create and output a message at C.P. */ <BR>&nbsp;&nbsp; 
      sprintf(msg, " (%d, %d)", getx(), gety()); <BR>&nbsp;&nbsp; outtext(msg); 
      <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>函数名: movetext <BR>功&nbsp; 能: 将屏幕文本从一个矩形区域拷贝到另一个矩形区域 <BR>用&nbsp; 法: int 
      movetext(int left, int top, int right, int bottom, <BR>&nbsp; int newleft, 
      int newtop); <BR>程序例: <BR>#include &lt;conio.h&gt; <BR>#include 
      &lt;string.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char *str = "This is a test 
      string"; <BR>
      <P>&nbsp;&nbsp; clrscr(); <BR>&nbsp;&nbsp; cputs(str); <BR>&nbsp;&nbsp; 
      getch(); <BR>
      <P>&nbsp;&nbsp; movetext(1, 1, strlen(str), 2, 10, 10); <BR>&nbsp;&nbsp; 
      getch(); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: moveto <BR>功&nbsp; 能: 将CP移到(x, y) <BR>用&nbsp; 法: void far 
      moveto(int x, int y); <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; 
      char msg[80]; <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; /* move the C.P. to location (20, 30) */ <BR>&nbsp;&nbsp; 
      moveto(20, 30); <BR>
      <P>&nbsp;&nbsp; /* plot a pixel at the C.P. */ <BR>&nbsp;&nbsp; 
      putpixel(getx(), gety(), getmaxcolor()); <BR>
      <P>&nbsp;&nbsp; /* create and output a message at (20, 30) */ 
      <BR>&nbsp;&nbsp; sprintf(msg, " (%d, %d)", getx(), gety()); 
      <BR>&nbsp;&nbsp; outtextxy(20, 30, msg); <BR>
      <P>&nbsp;&nbsp; /* move to (100, 100) */ <BR>&nbsp;&nbsp; moveto(100, 
      100); <BR>
      <P>&nbsp;&nbsp; /* plot a pixel at the C.P. */ <BR>&nbsp;&nbsp; 
      putpixel(getx(), gety(), getmaxcolor()); <BR>
      <P>&nbsp;&nbsp; /* create and output a message at C.P. */ <BR>&nbsp;&nbsp; 
      sprintf(msg, " (%d, %d)", getx(), gety()); <BR>&nbsp;&nbsp; outtext(msg); 
      <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>函数名: movemem <BR>功&nbsp; 能: 移动一块字节 <BR>用&nbsp; 法: void movemem(void 
      *source, void *destin, unsigned len); <BR>程序例: <BR>
      <P>#include &lt;mem.h&gt; <BR>#include &lt;alloc.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;string.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char *source = "Borland 
      International"; <BR>&nbsp;&nbsp; char *destination; <BR>&nbsp;&nbsp; int 
      length; <BR>
      <P>&nbsp;&nbsp; length = strlen(source); <BR>&nbsp;&nbsp; destination = 
      malloc(length + 1); <BR>&nbsp;&nbsp; movmem(source,destination,length); 
      <BR>&nbsp;&nbsp; printf("%s\n",destination); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: normvideo <BR>功&nbsp; 能: 选择正常亮度字符 <BR>用&nbsp; 法: void 
      normvideo(void); <BR>程序例: <BR>
      <P>#include &lt;conio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; normvideo(); <BR>&nbsp;&nbsp; 
      cprintf("NORMAL Intensity Text\r\n"); <BR>&nbsp;&nbsp; return 0; <BR>} 
      <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: nosound <BR>功&nbsp; 能: 关闭PC扬声器 <BR>用&nbsp; 法: void nosound(void); 
      <BR>程序例: <BR>
      <P>/* Emits a 7-Hz tone for 10 seconds. <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp; True story: 7 Hz is the resonant frequency of 
      a chicken's skull cavity. <BR>&nbsp;&nbsp;&nbsp;&nbsp; This was determined 
      empirically in Australia, where a new factory <BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      generating 7-Hz tones was located too close to a chicken ranch: 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp; When the factory started up, all the chickens 
      died. <BR>
      <P>&nbsp;&nbsp;&nbsp;&nbsp; Your PC may not be able to emit a 7-Hz tone. 
      <BR>*/ <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; sound(7); <BR>&nbsp;&nbsp; 
      delay(10000); <BR>&nbsp;&nbsp; nosound(); <BR>} <BR>&nbsp; <BR>
      <HR width="94%" color=#ee9b73 SIZE=1>
    </TD>
    <TD class=tt3 vAlign=bottom width="8%" bgColor=#e0e0e0><STRONG><A 
      href="http://www.hjflying.8u8.com/cl/032.htm">后一页</A><BR><A 
      href="http://www.hjflying.8u8.com/cl/030.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></TR></TBODY></TABLE></BODY></HTML>

⌨️ 快捷键说明

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