📄 fr.htm
字号:
<HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"> <META NAME="Author" CONTENT="wdg"> <META NAME="GENERATOR" CONTENT="Mozilla/4.03 [en] (Win95; I) [Netscape]"> <TITLE>fr</TITLE></HEAD><BODY> <P>函数名: raise<BR>功 能: 向正在执行的程序发送一个信号<BR>用 法: int raise(int sig);<BR>程序例:<P>#include <signal.h><P>int main(void)<BR>{<BR> int a, b;<P> a = 10;<BR> b = 0;<BR> if (b == 0)<BR> /* preempt divide by zero error */<BR> raise(SIGFPE);<BR> a = a / b;<BR> return 0;<BR>}<BR> <BR> <P>函数名: rand<BR>功 能: 随机数发生器<BR>用 法: void rand(void);<BR>程序例:<P>#include <stdlib.h><BR>#include <stdio.h><P>int main(void)<BR>{<BR> int i;<P> printf("Ten random numbers from 0 to 99\n\n");<BR> for(i=0; i<10; i++)<BR> printf("%d\n", rand() % 100);<BR> return 0;<BR>}<BR> <BR> <P>函数名: randbrd<BR>功 能: 随机块读<BR>用 法: int randbrd(struct fcb *fcbptr, int reccnt);<BR>程序例:<P>#include <process.h><BR>#include <string.h><BR>#include <stdio.h><BR>#include <dos.h><P>int main(void)<BR>{<BR> char far *save_dta;<BR> char line[80], buffer[256];<BR> struct fcb blk;<BR> int i, result;<P> /* get user input file name for dta */<BR> printf("Enter drive and file name (no path - i.e. a:file.dat)\n");<BR> gets(line);<P> /* put file name in fcb */<BR> if (!parsfnm(line, &blk, 1))<BR> {<BR> printf("Error in call to parsfnm\n");<BR> exit(1);<BR> }<BR> printf("Drive #%d File: %s\n\n", blk.fcb_drive,blk.fcb_name);<P> /* open file with DOS FCB open file */<BR> bdosptr(0x0F, &blk, 0);<P> /* save old dta, and set new one */<BR> save_dta = getdta();<BR> setdta(buffer);<P> /* set up info for the new dta */<BR> blk.fcb_recsize = 128;<BR> blk.fcb_random = 0L;<BR> result = randbrd(&blk, 1);<P> /* check results from randbrd */<BR> if (!result)<BR> printf("Read OK\n\n");<BR> else<BR> {<BR> perror("Error during read");<BR> exit(1);<BR> }<P> /* read in data from the new dta */<BR> printf("The first 128 characters are:\n");<BR> for (i=0; i<128; i++)<BR> putchar(buffer[i]);<P> /* restore previous dta */<BR> setdta(save_dta);<P> return 0;<BR>}<BR> <P>函数名: randbwr<BR>功 能: 随机块写<BR>用 法: int randbwr(struct fcp *fcbptr, int reccnt);<BR>程序例:<P>#include <process.h><BR>#include <string.h><BR>#include <stdio.h><BR>#include <dos.h><P>int main(void)<BR>{<BR> char far *save_dta;<BR> char line[80];<BR> char buffer[256] = "RANDBWR test!";<BR> struct fcb blk;<BR> int result;<P> /* get new file name from user */<BR> printf("Enter a file name to create (no path - ie. a:file.dat\n");<BR> gets(line);<P> /* parse the new file name to the dta */<BR> parsfnm(line,&blk,1);<BR> printf("Drive #%d File: %s\n", blk.fcb_drive, blk.fcb_name);<P> /* request DOS services to create file */<BR> if (bdosptr(0x16, &blk, 0) == -1)<BR> {<BR> perror("Error creating file");<BR> exit(1);<BR> }<P> /* save old dta and set new dta */<BR> save_dta = getdta();<BR> setdta(buffer);<P> /* write new records */<BR> blk.fcb_recsize = 256;<BR> blk.fcb_random = 0L;<BR> result = randbwr(&blk, 1);<P> if (!result)<BR> printf("Write OK\n");<BR> else<BR> {<BR> perror("Disk error");<BR> exit(1);<BR> }<P> /* request DOS services to close the file */<BR> if (bdosptr(0x10, &blk, 0) == -1)<BR> {<BR> perror("Error closing file");<BR> exit(1);<BR> }<P> /* reset the old dta */<BR> setdta(save_dta);<P> return 0;<BR>}<BR> <BR> <P>函数名: random<BR>功 能: 随机数发生器<BR>用 法: int random(int num);<BR>程序例:<P>#include <stdlib.h><BR>#include <stdio.h><BR>#include <time.h><P>/* prints a random number in the range 0 to 99 */<BR>int main(void)<BR>{<BR> randomize();<BR> printf("Random number in the 0-99 range: %d\n", random(100));<BR> return 0;<BR>}<BR> <BR> <P>函数名: randomize<BR>功 能: 初始化随机数发生器<BR>用 法: void randomize(void);<BR>程序例:<P>#include <stdlib.h><BR>#include <stdio.h><BR>#include <time.h><P>int main(void)<BR>{<BR> int i;<P> randomize();<BR> printf("Ten random numbers from 0 to 99\n\n");<BR> for(i=0; i<10; i++)<BR> printf("%d\n", rand() % 100);<BR> return 0;<BR>}<BR> <BR> <P>函数名: read<BR>功 能: 从文件中读<BR>用 法: int read(int handle, void *buf, int nbyte);<BR>程序例:<P>#include <stdio.h><BR>#include <io.h><BR>#include <alloc.h><BR>#include <fcntl.h><BR>#include <process.h><BR>#include <sys\stat.h><P>int main(void)<BR>{<BR> void *buf;<BR> int handle, bytes;<P> buf = malloc(10);<P>/*<BR> Looks for a file in the current directory named TEST.$$$and attempts<BR> to read 10 bytes from it. To use this example youshould create the<BR> file TEST.$$$<BR>*/<BR> if ((handle =<BR> open("TEST.$$$", O_RDONLY | O_BINARY,S_IWRITE | S_IREAD)) == -1)<BR> {<BR> printf("Error Opening File\n");<BR> exit(1);<BR> }<P> if ((bytes = read(handle, buf, 10)) == -1) {<BR> printf("Read Failed.\n");<BR> exit(1);<BR> }<BR> else {<BR> printf("Read: %d bytes read.\n", bytes);<BR> }<BR> return 0;<BR>}<BR> <BR> <P>函数名: realloc<BR>功 能: 重新分配主存<BR>用 法: void *realloc(void *ptr, unsigned newsize);<BR>程序例:<P>#include <stdio.h><BR>#include <alloc.h><BR>#include <string.h><P>int main(void)<BR>{<BR> char *str;<P> /* allocate memory for string */<BR> str = malloc(10);<P> /* copy "Hello" into string */<BR> strcpy(str, "Hello");<P> printf("String is %s\n Address is %p\n", str, str);<BR> str = realloc(str, 20);<BR> printf("String is %s\n New address is %p\n", str,str);<P> /* free memory */<BR> free(str);<P> return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -