📄 王大刚--c语言编程宝典--f.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/025.htm -->
<HTML><HEAD><TITLE>王大刚-->C语言编程宝典-->F</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大刚 C语言编程宝典 F" name=keywords>
<META content="王大刚 - C语言编程宝典 - F" 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/026.htm">后一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/024.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>F</FONT></B></CENTER>
<HR width="94%" color=#ee9b73 SIZE=1>
<P>函数名: fabs <BR>功 能: 返回浮点数的绝对值 <BR>用 法: double fabs(double
x); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <math.h> <BR>
<P>int main(void) <BR>{ <BR> float number = -1234.0;
<BR>
<P> printf("number: %f absolute value: %f\n",
<BR> number, fabs(number)); <BR> return 0; <BR>}
<BR> <BR> <BR> <BR>
<P>函数名: farcalloc <BR>功 能: 从远堆栈中申请空间 <BR>用 法: void far
*farcalloc(unsigned long units, unsigned ling unitsz); <BR>程序例:
<BR>#include <stdio.h> <BR>#include <alloc.h> <BR>#include
<string.h> <BR>#include <dos.h> <BR>
<P>int main(void) <BR>{ <BR> char far *fptr; <BR>
char *str = "Hello"; <BR>
<P> /* allocate memory for the far pointer */ <BR>
fptr = farcalloc(10, sizeof(char)); <BR>
<P> /* copy "Hello" into allocated memory */ <BR>
/* <BR> Note: movedata is used because you
<BR> might be in a small data model, in
<BR> which case a normal string copy routine
<BR> can not be used since it assumes the
<BR> pointer size is near. <BR>
*/ <BR> movedata(FP_SEG(str), FP_OFF(str),
<BR> FP_SEG(fptr), FP_OFF(fptr),
<BR>
strlen(str)); <BR>
<P> /* display string (note the F modifier) */
<BR> printf("Far string is: %Fs\n", fptr); <BR>
<P> /* free the memory */ <BR> farfree(fptr); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: farcoreleft <BR>功 能: 返回远堆中未作用存储区大小 <BR>用 法: long
farcoreleft(void); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <alloc.h> <BR>
<P>int main(void) <BR>{ <BR> printf("The difference between
the\ <BR> highest allocated block in the\
<BR> far\n");
<BR> printf("heap and the top of the far heap\
<BR> is: %lu
bytes\n", farcoreleft()); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: farfree <BR>功 能: 从远堆中释放一块 <BR>用 法: void farfree(void);
<BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <alloc.h> <BR>#include
<string.h> <BR>#include <dos.h> <BR>
<P>int main(void) <BR>{ <BR> char far *fptr; <BR>
char *str = "Hello"; <BR>
<P> /* allocate memory for the far pointer */ <BR>
fptr = farcalloc(10, sizeof(char)); <BR>
<P> /* copy "Hello" into allocated memory */ <BR>
/* <BR> Note: movedata is used because you
might be in a small data model, <BR> in
which case a normal string copy routine can't be used since it
<BR> assumes the pointer size is near.
<BR> */ <BR> movedata(FP_SEG(str), FP_OFF(str),
<BR>
FP_SEG(fptr), FP_OFF(fptr),
<BR>
strlen(str)); <BR>
<P> /* display string (note the F modifier) */
<BR> printf("Far string is: %Fs\n", fptr); <BR>
<P> /* free the memory */ <BR> farfree(fptr); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: farmalloc <BR>功 能: 从远堆中分配存储块 <BR>用 法: void far
*farmalloc(unsigned long size); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <alloc.h> <BR>#include
<string.h> <BR>#include <dos.h> <BR>
<P>int main(void) <BR>{ <BR> char far *fptr; <BR>
char *str = "Hello"; <BR>
<P> /* allocate memory for the far pointer */ <BR>
fptr = farmalloc(10); <BR>
<P> /* copy "Hello" into allocated memory */ <BR>
/* <BR> Note: movedata is used because we
might <BR> be in a small data model, in
which case <BR> a normal string copy routine
can not be <BR> used since it assumes the
pointer size <BR> is near. <BR>
*/ <BR> movedata(FP_SEG(str), FP_OFF(str),
<BR> FP_SEG(fptr), FP_OFF(fptr),
<BR> strlen(str)); <BR>
<P> /* display string (note the F modifier) */
<BR> printf("Far string is: %Fs\n", fptr); <BR>
<P> /* free the memory */ <BR> farfree(fptr); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: farrealloc <BR>功 能: 调整远堆中的分配块 <BR>用 法: void far
*farrealloc(void far *block, unsigned long newsize); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <alloc.h> <BR>
<P>int main(void) <BR>{ <BR> char far *fptr; <BR>
<P> fptr = farmalloc(10); <BR> printf("First
address: %Fp\n", fptr); <BR> fptr = farrealloc(fptr,20);
<BR> printf("New address : %Fp\n", fptr);
<BR> farfree(fptr); <BR> return 0; <BR>}
<BR> <BR> <BR>
<P>函数名: fclose <BR>功 能: 关闭一个流 <BR>用 法: int fclose(FILE
*stream); <BR>程序例: <BR>
<P>#include <string.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> FILE *fp; <BR> char
buf[11] = "0123456789"; <BR>
<P> /* create a file containing 10 bytes */ <BR>
fp = fopen("DUMMY.FIL", "w"); <BR> fwrite(&buf,
strlen(buf), 1, fp); <BR>
<P> /* close the file */ <BR> fclose(fp);
<BR> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: fcloseall <BR>功 能: 关闭打开流 <BR>用 法: int fcloseall(void);
<BR>程序例: <BR>
<P>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> int streams_closed; <BR>
<P> /* open two streams */ <BR> fopen("DUMMY.ONE",
"w"); <BR> fopen("DUMMY.TWO", "w"); <BR>
<P> /* close the open streams */ <BR>
streams_closed = fcloseall(); <BR>
<P> if (streams_closed == EOF)
<BR> /* issue an error message */
<BR> perror("Error"); <BR> else
<BR> /* print result of fcloseall() function
*/ <BR> printf("%d streams were closed.\n",
streams_closed); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: fcvt <BR>功 能: 把一个浮点数转换为字符串 <BR>用 法: char *fcvt(double
value, int ndigit, int *decpt, int *sign); <BR>程序例: <BR>
<P>#include <stdlib.h> <BR>#include <stdio.h> <BR>#include
<conio.h> <BR>
<P>int main(void) <BR>{ <BR> char *string; <BR>
double value; <BR> int dec, sign; <BR> int ndig =
10; <BR>
<P> clrscr(); <BR> value = 9.876; <BR>
string = ecvt(value, ndig, &dec, &sign); <BR>
printf("string = %s dec = %d \
<BR> sign = %d\n",
string, dec, sign); <BR>
<P> value = -123.45; <BR> ndig= 15;
<BR> string = ecvt(value,ndig,&dec,&sign);
<BR> printf("string = %s dec = %d sign = %d\n",
<BR> string, dec,
sign); <BR> <BR>
<P> value = 0.6789e5; /* scientific
<BR>
notation */ <BR> ndig = 5; <BR> string =
ecvt(value,ndig,&dec,&sign); <BR> printf("string =
%s dec = %d\
<BR> sign = %d\n",
string, dec, sign); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: fdopen <BR>功 能: 把流与一个文件句柄相接 <BR>用 法: FILE *fdopen(int
handle, char *type); <BR>程序例: <BR>
<P>#include <sys\stat.h> <BR>#include <stdio.h> <BR>#include
<fcntl.h> <BR>#include <io.h> <BR>
<P>int main(void) <BR>{ <BR> int handle; <BR> FILE
*stream; <BR>
<P> /* open a file */ <BR> handle =
open("DUMMY.FIL", O_CREAT, <BR> S_IREAD | S_IWRITE);
<BR>
<P> /* now turn the handle into a stream */ <BR>
stream = fdopen(handle, "w"); <BR>
<P> if (stream == NULL) <BR>
printf("fdopen failed\n"); <BR> else <BR> {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -