📄 ff.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>ff</TITLE></HEAD><BODY> <BR> <P>函数名: fabs<BR>功 能: 返回浮点数的绝对值<BR>用 法: double fabs(double x);<BR>程序例:<P>#include <stdio.h><BR>#include <math.h><P>int main(void)<BR>{<BR> float number = -1234.0;<P> printf("number: %f absolute value: %f\n",<BR> number, fabs(number));<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: farcalloc<BR>功 能: 从远堆栈中申请空间<BR>用 法: void far *farcalloc(unsigned long units, unsigned lingunitsz);<BR>程序例:<BR>#include <stdio.h><BR>#include <alloc.h><BR>#include <string.h><BR>#include <dos.h><P>int main(void)<BR>{<BR> char far *fptr;<BR> char *str = "Hello";<P> /* allocate memory for the far pointer */<BR> fptr = farcalloc(10, sizeof(char));<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));<P> /* display string (note the F modifier) */<BR> printf("Far string is: %Fs\n", fptr);<P> /* free the memory */<BR> farfree(fptr);<P> return 0;<BR>}<BR> <BR> <BR> <P>函数名: farcoreleft<BR>功 能: 返回远堆中未作用存储区大小<BR>用 法: long farcoreleft(void);<BR>程序例:<P>#include <stdio.h><BR>#include <alloc.h><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: %lubytes\n", farcoreleft());<P> return 0;<BR>}<BR> <BR> <BR> <P>函数名: farfree<BR>功 能: 从远堆中释放一块<BR>用 法: void farfree(void);<BR>程序例:<P>#include <stdio.h><BR>#include <alloc.h><BR>#include <string.h><BR>#include <dos.h><P>int main(void)<BR>{<BR> char far *fptr;<BR> char *str = "Hello";<P> /* allocate memory for the far pointer */<BR> fptr = farcalloc(10, sizeof(char));<P> /* copy "Hello" into allocated memory */<BR> /*<BR> Note: movedata is used because you mightbe in a small data model,<BR> in which case a normal string copy routinecan'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));<P> /* display string (note the F modifier) */<BR> printf("Far string is: %Fs\n", fptr);<P> /* free the memory */<BR> farfree(fptr);<P> return 0;<BR>}<BR> <BR> <BR> <P>函数名: farmalloc<BR>功 能: 从远堆中分配存储块<BR>用 法: void far *farmalloc(unsigned long size);<BR>程序例:<P>#include <stdio.h><BR>#include <alloc.h><BR>#include <string.h><BR>#include <dos.h><P>int main(void)<BR>{<BR> char far *fptr;<BR> char *str = "Hello";<P> /* allocate memory for the far pointer */<BR> fptr = farmalloc(10);<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 notbe<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));<P> /* display string (note the F modifier) */<BR> printf("Far string is: %Fs\n", fptr);<P> /* free the memory */<BR> farfree(fptr);<P> return 0;<BR>}<BR> <BR> <BR> <P>函数名: farrealloc<BR>功 能: 调整远堆中的分配块<BR>用 法: void far *farrealloc(void far *block, unsigned long newsize);<BR>程序例:<P>#include <stdio.h><BR>#include <alloc.h><P>int main(void)<BR>{<BR> char far *fptr;<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> <P>函数名: fclose<BR>功 能: 关闭一个流<BR>用 法: int fclose(FILE *stream);<BR>程序例:<P>#include <string.h><BR>#include <stdio.h><P>int main(void)<BR>{<BR> FILE *fp;<BR> char buf[11] = "0123456789";<P> /* create a file containing 10 bytes */<BR> fp = fopen("DUMMY.FIL", "w");<BR> fwrite(&buf, strlen(buf), 1, fp);<P> /* close the file */<BR> fclose(fp);<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: fcloseall<BR>功 能: 关闭打开流<BR>用 法: int fcloseall(void);<BR>程序例:<P>#include <stdio.h><P>int main(void)<BR>{<BR> int streams_closed;<P> /* open two streams */<BR> fopen("DUMMY.ONE", "w");<BR> fopen("DUMMY.TWO", "w");<P> /* close the open streams */<BR> streams_closed = fcloseall();<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);<P> return 0;<BR>}<BR> <BR> <P>函数名: fcvt<BR>功 能: 把一个浮点数转换为字符串<BR>用 法: char *fcvt(double value, int ndigit, int *decpt, int *sign);<BR>程序例:<P>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><P>int main(void)<BR>{<BR> char *string;<BR> double value;<BR> int dec, sign;<BR> int ndig = 10;<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);<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> <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);<P> return 0;<BR>}<BR> <BR> <BR> <P>函数名: fdopen<BR>功 能: 把流与一个文件句柄相接<BR>用 法: FILE *fdopen(int handle, char *type);<BR>程序例:<P>#include <sys\stat.h><BR>#include <stdio.h><BR>#include <fcntl.h><BR>#include <io.h><P>int main(void)<BR>{<BR> int handle;<BR> FILE *stream;<P> /* open a file */<BR> handle = open("DUMMY.FIL", O_CREAT,<BR> S_IREAD | S_IWRITE);<P> /* now turn the handle into a stream */<BR> stream = fdopen(handle, "w");<P> if (stream == NULL)<BR> printf("fdopen failed\n");<BR> else<BR> {<BR> fprintf(stream, "Hello world\n");<BR> fclose(stream);<BR> }<BR> return 0;<BR>}<BR> <BR> <P>函数名: feof<BR>功 能: 检测流上的文件结束符<BR>用 法: int feof(FILE *stream);<BR>程序例:<P>#include <stdio.h><P>int main(void)<BR>{<BR> FILE *stream;<P> /* open a file for reading */<BR> stream = fopen("DUMMY.FIL", "r");<P> /* read a character from the file */<BR> fgetc(stream);<P> /* check for EOF */<BR> if (feof(stream))<BR> printf("We have reached end-of-file\n");<P> /* close the file */<BR> fclose(stream);<BR> return 0;<BR>}<BR> <BR> <P>函数名: ferror<BR>功 能: 检测流上的错误<BR>用 法: int ferror(FILE *stream);<BR>程序例:<P>#include <stdio.h><P>int main(void)<BR>{<BR> FILE *stream;<P> /* open a file for writing */<BR> stream = fopen("DUMMY.FIL", "w");<P> /* force an error condition by attempting to read */<BR> (void) getc(stream);<P> if (ferror(stream)) /* test for an error on the stream*/<BR> {<BR> /* display an error message */<BR> printf("Error reading from DUMMY.FIL\n");<P> /* reset the error and EOF indicators*/<BR> clearerr(stream);<BR> }<P> fclose(stream);<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: fflush<BR>功 能: 清除一个流<BR>用 法: int fflush(FILE *stream);<BR>程序例:<P>#include <string.h><BR>#include <stdio.h><BR>#include <conio.h><BR>#include <io.h><P>void flush(FILE *stream);<P>int main(void)<BR>{<BR> FILE *stream;<BR> char msg[] = "This is a test";<P> /* create a file */<BR> stream = fopen("DUMMY.FIL", "w");<P> /* write some data to the file */<BR> fwrite(msg, strlen(msg), 1, stream);<P> clrscr();<BR> printf("Press any key to flush\<BR> DUMMY.FIL:");<BR> getch();<P> /* flush the data to DUMMY.FIL without\<BR> closing it */<BR> flush(stream);<P> printf("\nFile was flushed, Press any key\<BR> to quit:");<BR> getch();<BR> return 0;<BR>}<P>void flush(FILE *stream)<BR>{<BR> int duphandle;<P> /* flush the stream's internal buffer */<BR> fflush(stream);<P> /* make a duplicate file handle */<BR> duphandle = dup(fileno(stream));<P> /* close the duplicate handle to flush\<BR> the DOS buffer */<BR> close(duphandle);<BR>}<BR> <BR> <BR> <P>函数名: fgetc<BR>功 能: 从流中读取字符<BR>用 法: int fgetc(FILE *stream);<BR>程序例:<P>#include <string.h><BR>#include <stdio.h><BR>#include <conio.h><P>int main(void)<BR>{<BR> FILE *stream;<BR> char string[] = "This is a test";<BR> char ch;<P> /* open a file for update */<BR> stream = fopen("DUMMY.FIL", "w+");<P> /* write a string into the file */<BR> fwrite(string, strlen(string), 1, stream);<P> /* seek to the beginning of the file */<BR> fseek(stream, 0, SEEK_SET);<P> do<BR> {<BR> /* read a char from the file */<BR> ch = fgetc(stream);<P> /* display the character */<BR> putch(ch);<BR> } while (ch != EOF);<P> fclose(stream);<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: fgetchar<BR>功 能: 从流中读取字符<BR>用 法: int fgetchar(void);<BR>程序例:<P>#include <stdio.h><P>int main(void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -