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

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

📁 初学者的良师益友。其中包括C的全部教程。
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/035.htm -->
<HTML><HEAD><TITLE>王大刚-->C语言编程宝典-->R</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大刚 C语言编程宝典 R" name=keywords>
<META content="王大刚 - C语言编程宝典 - R" 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/036.htm">后一页</A><BR><A 
      href="http://www.hjflying.8u8.com/cl/034.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>R</FONT></B></CENTER>
      <HR width="94%" color=#ee9b73 SIZE=1>

      <P>函数名: raise <BR>功&nbsp; 能: 向正在执行的程序发送一个信号 <BR>用&nbsp; 法: int raise(int 
      sig); <BR>程序例: <BR>
      <P>#include &lt;signal.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; int a, b; <BR>
      <P>&nbsp;&nbsp; a = 10; <BR>&nbsp;&nbsp; b = 0; <BR>&nbsp;&nbsp; if (b == 
      0) <BR>&nbsp;&nbsp; /* preempt divide by zero error */ 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise(SIGFPE); <BR>&nbsp;&nbsp; a = a / 
      b; <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: rand <BR>功&nbsp; 能: 随机数发生器 <BR>用&nbsp; 法: void rand(void); 
      <BR>程序例: <BR>
      <P>#include &lt;stdlib.h&gt; <BR>#include &lt;stdio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; int i; <BR>
      <P>&nbsp;&nbsp; printf("Ten random numbers from 0 to 99\n\n"); 
      <BR>&nbsp;&nbsp; for(i=0; i&lt;10; i++) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("%d\n", rand() % 100); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; 
      <BR>&nbsp; <BR>
      <P>函数名: randbrd <BR>功&nbsp; 能: 随机块读 <BR>用&nbsp; 法: int randbrd(struct fcb 
      *fcbptr, int reccnt); <BR>程序例: <BR>
      <P>#include &lt;process.h&gt; <BR>#include &lt;string.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;dos.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char far *save_dta; 
      <BR>&nbsp;&nbsp; char line[80], buffer[256]; <BR>&nbsp;&nbsp; struct fcb 
      blk; <BR>&nbsp;&nbsp; int i, result; <BR>
      <P>&nbsp;&nbsp; /* get user input file name for dta */ <BR>&nbsp;&nbsp; 
      printf("Enter drive and file name (no path - i.e. a:file.dat)\n"); 
      <BR>&nbsp;&nbsp; gets(line); <BR>
      <P>&nbsp;&nbsp; /* put file name in fcb */ <BR>&nbsp;&nbsp; if 
      (!parsfnm(line, &amp;blk, 1)) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Error in call to parsfnm\n"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; } 
      <BR>&nbsp;&nbsp; printf("Drive #%d&nbsp; File: %s\n\n", blk.fcb_drive, 
      blk.fcb_name); <BR>
      <P>&nbsp;&nbsp; /* open file with DOS FCB open file */ <BR>&nbsp;&nbsp; 
      bdosptr(0x0F, &amp;blk, 0); <BR>
      <P>&nbsp;&nbsp; /* save old dta, and set new one */ <BR>&nbsp;&nbsp; 
      save_dta = getdta(); <BR>&nbsp;&nbsp; setdta(buffer); <BR>
      <P>&nbsp;&nbsp; /* set up info for the new dta */ <BR>&nbsp;&nbsp; 
      blk.fcb_recsize = 128; <BR>&nbsp;&nbsp; blk.fcb_random = 0L; 
      <BR>&nbsp;&nbsp; result = randbrd(&amp;blk, 1); <BR>
      <P>&nbsp;&nbsp; /* check results from randbrd */ <BR>&nbsp;&nbsp; if 
      (!result) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Read OK\n\n"); 
      <BR>&nbsp;&nbsp; else <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("Error during read"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* read in data from the new dta */ <BR>&nbsp;&nbsp; 
      printf("The first 128 characters are:\n"); <BR>&nbsp;&nbsp; for (i=0; 
      i&lt;128; i++) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putchar(buffer[i]); <BR>
      <P>&nbsp;&nbsp; /* restore previous dta */ <BR>&nbsp;&nbsp; 
      setdta(save_dta); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>
      <P>函数名: randbwr <BR>功&nbsp; 能: 随机块写 <BR>用&nbsp; 法: int randbwr(struct fcp 
      *fcbptr, int reccnt); <BR>程序例: <BR>
      <P>#include &lt;process.h&gt; <BR>#include &lt;string.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;dos.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char far *save_dta; 
      <BR>&nbsp;&nbsp; char line[80]; <BR>&nbsp;&nbsp; char buffer[256] = 
      "RANDBWR test!"; <BR>&nbsp;&nbsp; struct fcb blk; <BR>&nbsp;&nbsp; int 
      result; <BR>
      <P>&nbsp;&nbsp; /* get new file name from user */ <BR>&nbsp;&nbsp; 
      printf("Enter a file name to create (no path - ie. a:file.dat\n"); 
      <BR>&nbsp;&nbsp; gets(line); <BR>
      <P>&nbsp;&nbsp; /* parse the new file name to the dta */ <BR>&nbsp;&nbsp; 
      parsfnm(line,&amp;blk,1); <BR>&nbsp;&nbsp; printf("Drive #%d&nbsp; File: 
      %s\n", blk.fcb_drive, blk.fcb_name); <BR>
      <P>&nbsp;&nbsp; /* request DOS services to create file */ <BR>&nbsp;&nbsp; 
      if (bdosptr(0x16, &amp;blk, 0) == -1) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("Error creating file"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* save old dta and set new dta */ <BR>&nbsp;&nbsp; 
      save_dta = getdta(); <BR>&nbsp;&nbsp; setdta(buffer); <BR>
      <P>&nbsp;&nbsp; /* write new records */ <BR>&nbsp;&nbsp; blk.fcb_recsize = 
      256; <BR>&nbsp;&nbsp; blk.fcb_random = 0L; <BR>&nbsp;&nbsp; result = 
      randbwr(&amp;blk, 1); <BR>
      <P>&nbsp;&nbsp; if (!result) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      printf("Write OK\n"); <BR>&nbsp;&nbsp; else <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("Disk error"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* request DOS services to close the file */ 
      <BR>&nbsp;&nbsp; if (bdosptr(0x10, &amp;blk, 0) == -1) <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("Error closing file"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; /* reset the old dta */ <BR>&nbsp;&nbsp; setdta(save_dta); 
      <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: random <BR>功&nbsp; 能: 随机数发生器 <BR>用&nbsp; 法: int random(int num); 
      <BR>程序例: <BR>
      <P>#include &lt;stdlib.h&gt; <BR>#include &lt;stdio.h&gt; <BR>#include 
      &lt;time.h&gt; <BR>
      <P>/* prints a random number in the range 0 to 99 */ <BR>int main(void) 
      <BR>{ <BR>&nbsp;&nbsp; randomize(); <BR>&nbsp;&nbsp; printf("Random number 
      in the 0-99 range: %d\n", random (100)); <BR>&nbsp;&nbsp; return 0; <BR>} 
      <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: randomize <BR>功&nbsp; 能: 初始化随机数发生器 <BR>用&nbsp; 法: void 
      randomize(void); <BR>程序例: <BR>
      <P>#include &lt;stdlib.h&gt; <BR>#include &lt;stdio.h&gt; <BR>#include 
      &lt;time.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; int i; <BR>
      <P>&nbsp;&nbsp; randomize(); <BR>&nbsp;&nbsp; printf("Ten random numbers 
      from 0 to 99\n\n"); <BR>&nbsp;&nbsp; for(i=0; i&lt;10; i++) 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%d\n", rand() % 100); 
      <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: read <BR>功&nbsp; 能: 从文件中读 <BR>用&nbsp; 法: int read(int handle, void 
      *buf, int nbyte); <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;io.h&gt; <BR>#include 
      &lt;alloc.h&gt; <BR>#include &lt;fcntl.h&gt; <BR>#include 
      &lt;process.h&gt; <BR>#include &lt;sys\stat.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; void *buf; <BR>&nbsp;&nbsp; int 
      handle, bytes; <BR>
      <P>&nbsp;&nbsp; buf = malloc(10); <BR>
      <P>/* <BR>&nbsp;&nbsp; Looks for a file in the current directory named 
      TEST.$$$ and attempts <BR>&nbsp;&nbsp; to read 10 bytes from it.&nbsp; To 
      use this example you should create the <BR>&nbsp;&nbsp; file TEST.$$$ 
      <BR>*/ <BR>&nbsp;&nbsp; if ((handle = <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      open("TEST.$$$", O_RDONLY | O_BINARY, S_IWRITE | S_IREAD)) == -1) 
      <BR>&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Error 
      Opening File\n"); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); 
      <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; if ((bytes = read(handle, buf, 10)) == -1) { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Read Failed.\n"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; } 
      <BR>&nbsp;&nbsp; else { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Read: 
      %d bytes read.\n", bytes); <BR>&nbsp;&nbsp; } <BR>&nbsp;&nbsp; return 0; 
      <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: realloc <BR>功&nbsp; 能: 重新分配主存 <BR>用&nbsp; 法: void *realloc(void 
      *ptr, unsigned newsize); <BR>程序例: <BR>

⌨️ 快捷键说明

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