C语言FWord下载.docx
- 文档编号:17493333
- 上传时间:2022-12-06
- 格式:DOCX
- 页数:30
- 大小:24.27KB
C语言FWord下载.docx
《C语言FWord下载.docx》由会员分享,可在线阅读,更多相关《C语言FWord下载.docx(30页珍藏版)》请在冰豆网上搜索。
number,fabs(number));
return0;
}
farcalloc
从远堆栈中申请空间
voidfar*farcalloc(unsignedlongunits,unsignedlingunitsz);
alloc.h>
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=%s
dec=%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;
dec=%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);
#incl
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言
![提示](https://static.bdocx.com/images/bang_tan.gif)