?? 王大剛--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 + -