C语言库函数F类字母Word文档格式.docx
《C语言库函数F类字母Word文档格式.docx》由会员分享,可在线阅读,更多相关《C语言库函数F类字母Word文档格式.docx(31页珍藏版)》请在冰豆网上搜索。
![C语言库函数F类字母Word文档格式.docx](https://file1.bdocx.com/fileroot1/2023-1/31/d223ad34-1daf-4fd8-988e-45d3dd80d758/d223ad34-1daf-4fd8-988e-45d3dd80d7581.gif)
string.h>
dos.h>
charfar*fptr;
char*str="
Hello"
;
/*allocatememoryforthefarpointer*/
fptr=farcalloc(10,sizeof(char));
/*copy"
intoallocatedmemory*/
/*
Note:
movedataisusedbecauseyou
mightbeinasmalldatamodel,in
whichcaseanormalstringcopyroutine
cannotbeusedsinceitassumesthe
pointersizeisnear.
*/
movedata(FP_SEG(str),FP_OFF(str),
FP_SEG(fptr),FP_OFF(fptr),
strlen(str));
/*displaystring(notetheFmodifier)*/
Farstringis:
%Fs\n"
fptr);
/*freethememory*/
farfree(fptr);
farcoreleft
返回远堆中未作用存储区大小
longfarcoreleft(void);
Thedifferencebetweenthe\
highestallocatedblockinthe\
far\n"
);
heapandthetopofthefarheap\
is:
%lubytes\n"
farcoreleft());
farfree
从远堆中释放一块
voidfarfree(void);
movedataisusedbecauseyoumightbeinasmalldatamodel,
inwhichcaseanormalstringcopyroutinecan'
tbeusedsinceit
assumesthepointersizeisnear.
farmalloc
从远堆中分配存储块
voidfar*farmalloc(unsignedlongsize);
fptr=farmalloc(10);
movedataisusedbecausewemight
beinasmalldatamodel,inwhichcase
anormalstringcopyroutinecannotbe
usedsinceitassumesthepointersize
isnear.
farrealloc
调整远堆中的分配块
voidfar*farrealloc(voidfar*block,unsignedlongnewsize);
Firstaddress:
%Fp\n"
fptr=farrealloc(fptr,20);
Newaddress:
fclose
关闭一个流
intfclose(FILE*stream);
FILE*fp;
charbuf[11]="
0123456789"
/*createafilecontaining10bytes*/
fp=fopen("
DUMMY.FIL"
"
w"
fwrite(&
buf,strlen(buf),1,fp);
/*closethefile*/
fclose(fp);
fcloseall
关闭打开流
intfcloseall(void);
intstreams_closed;
/*opentwostreams*/
fopen("
DUMMY.ONE"
DUMMY.TWO"
/*closetheopenstreams*/
streams_closed=fcloseall();
if(streams_closed==EOF)
/*issueanerrormessage*/
perror("
Error"
else
/*printresultoffcloseall()function*/
%dstreamswereclosed.\n"
streams_closed);
fcvt
把一个浮点数转换为字符串
char*fcvt(doublevalue,intndigit,int*decpt,int*sign);
stdlib.h>
conio.h>
char*string;
doublevalue;
intdec,sign;
intndig=10;
clrscr();
value=9.876;
string=ecvt(value,ndig,&
dec,&
sign);
string=%sdec=%d\
sign=%d\n"
string,dec,sign);
value=-123.45;
ndig=15;
string=ecvt(value,ndig,&
dec,&
string=%sdec=%dsign=%d\n"
string,dec,sign);
value=0.6789e5;
/*scientific
notation*/
ndig=5;
string=%sdec=%d\
fdopen
把流与一个文件句柄相接
FILE*fdopen(inthandle,char*type);
sys\stat.h>
fcntl.h>
io.h>
inthandle;
FILE*stream;
/*openafile*/
handle=open("
O_CREAT,
S_IREAD│S_IWRITE);
/*nowturnthehandleintoastream*/
stream=fdopen(handle,"
if(stream==NULL)
fdopenfailed\n"
fprintf(stream,"
Helloworld\n"
fclose(stream);
feof
检测流上的文件结束符
intfeof(FILE*stream);
/*openafileforreading*/
stream=fopen("
r"
/*readacharacterfromthefile*/
fgetc(stream);
/*checkforEOF*/
if(feof(stream))
Wehavereachedend-of-file\n"
ferror
检测流上的错误
intferror(FILE*stream);
/*openafileforwriting*/
/*forceanerrorconditionbyattemptingtoread*/
(void)getc(stream);
if(ferror(stream))/*testforanerroronthestream*/
/*displayanerrormessage*/
ErrorreadingfromDUMMY.FIL\n"
/*resettheerrorandEOFindicators*/
clearerr(stream);
fflush
清除一个流
intfflush(FILE*stream);
voidflush(FILE*stream);
charmsg[]="
Thisisatest"
/*createafile*/
/*writesomedatatothefile*/
fwrite(msg,strlen(msg),1,stream);
Pressanykeytoflush\
DUMMY.FIL:
"
getch();
/*flushthedatatoDUMMY.FILwithout\
closingit*/
flush(stream);
\nFilewasflushed,Pressanykey\
toquit:
voidflush(FILE*stream)
intduphandle;
/*flushthestream'
sinternalbuffer*/
fflush(stream);
/*makeaduplicatefilehandle*/
duphandle=dup(fileno(stream));
/*closetheduplicatehandletoflush\
theDOSbuffer*/
close(duphandle);
fgetc
从流中读取字符
intfgetc(FILE*stream);
charstring[]="
charch;
/*openafileforupdate*/
w+"
/*writeastringintothefile*/
fwrite(string,strlen(string),1,stream);
/*seektothebeginningofthefile*/
fseek(stream,0,SEEK_SET);
do
/*readacharfromthefile*/
ch=fgetc(stream);
/*displaythecharacter*/
putch(ch);
}while(ch!
=EOF);
fgetchar
intfgetchar(void);
/*prompttheuserforinput*/
Enteracharacterfollowedby\
<
Enter>
:
"
/*readthecharacterfromstdin*/
ch=fgetchar();
/*displaywhatwasread*/
Thecharacterreadis:
'
%c'
\n"
ch);
fgetpos
取得当前文件的句柄
intfgetpos(FILE*stream);
fpos_tfilepos;
/*reportthefilepointerposition*/
fgetpos(stream,&
filepos);
Thefilepointerisatbyte\
%ld\n"
filepos);
fgets
从流中读取一字符串
char*fgets(char*string,intn,FILE*stream);
charmsg[20];
/*seektothestartofthefile*/
/*readastringfromthefile*/
fgets(msg,strlen(string)+1,stream);
/*displaythestring*/
%s"
msg);
filelength
取文件长度字节数
longfilelength(inthandle);
O_CREAT);
write(handle,buf,strlen(buf));
/*displaythesizeofthefile*/
filelengthinbytes:
%ld\n"
filelength(handle));
close(handle);