C语言函数大全F篇.docx
《C语言函数大全F篇.docx》由会员分享,可在线阅读,更多相关《C语言函数大全F篇.docx(15页珍藏版)》请在冰豆网上搜索。
![C语言函数大全F篇.docx](https://file1.bdocx.com/fileroot1/2023-1/8/09650c79-911a-455e-b4a3-e9b543672971/09650c79-911a-455e-b4a3-e9b5436729711.gif)
C语言函数大全F篇
F:
函数名:
farcalloc
功 能:
从远堆栈中申请空间
用 法:
voidfar*farcalloc(unsignedlongunits,unsignedlingunitsz);
程序例:
#include
#include
#include
#include
intmain(void)
{
charfar*fptr;
char*str="Hello";
/*allocatememoryforthefarpointer*/
fptr=farcalloc(10,sizeof(char));
/*copy"Hello"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)*/
printf("Farstringis:
%Fs\n",fptr);
/*freethememory*/
farfree(fptr);
return0;
}
函数名:
farcoreleft
功 能:
返回远堆中未作用存储区大小
用 法:
longfarcoreleft(void);
程序例:
#include
#include
intmain(void)
{
printf("Thedifferencebetweenthe\
highestallocatedblockinthe\
far\n");
printf("heapandthetopofthefarheap\
is:
%lubytes\n",farcoreleft());
return0;
}
函数名:
farfree
功 能:
从远堆中释放一块
用 法:
voidfarfree(void);
程序例:
#include
#include
#include
#include
intmain(void)
{
charfar*fptr;
char*str="Hello";
/*allocatememoryforthefarpointer*/
fptr=farcalloc(10,sizeof(char));
/*copy"Hello"intoallocatedmemory*/
/*
Note:
movedataisusedbecauseyoumightbeinasmalldatamodel,
inwhichcaseanormalstringcopyroutinecan'tbeusedsinceit
assumesthepointersizeisnear.
*/
movedata(FP_SEG(str),FP_OFF(str),
FP_SEG(fptr),FP_OFF(fptr),
strlen(str));
/*displaystring(notetheFmodifier)*/
printf("Farstringis:
%Fs\n",fptr);
/*freethememory*/
farfree(fptr);
return0;
}
函数名:
farmalloc
功 能:
从远堆中分配存储块
用 法:
voidfar*farmalloc(unsignedlongsize);
程序例:
#include
#include
#include
#include
intmain(void)
{
charfar*fptr;
char*str="Hello";
/*allocatememoryforthefarpointer*/
fptr=farmalloc(10);
/*copy"Hello"intoallocatedmemory*/
/*
Note:
movedataisusedbecausewemight
beinasmalldatamodel,inwhichcase
anormalstringcopyroutinecannotbe
usedsinceitassumesthepointersize
isnear.
*/
movedata(FP_SEG(str),FP_OFF(str),
FP_SEG(fptr),FP_OFF(fptr),
strlen(str));
/*displaystring(notetheFmodifier)*/
printf("Farstringis:
%Fs\n",fptr);
/*freethememory*/
farfree(fptr);
return0;
}
函数名:
farrealloc
功 能:
调整远堆中的分配块
用 法:
voidfar*farrealloc(voidfar*block,unsignedlongnewsize);
程序例:
#include
#include
intmain(void)
{
charfar*fptr;
fptr=farmalloc(10);
printf("Firstaddress:
%Fp\n",fptr);
fptr=farrealloc(fptr,20);
printf("Newaddress :
%Fp\n",fptr);
farfree(fptr);
return0;
}
函数名:
fcvt
功 能:
把一个浮点数转换为字符串
用 法:
char*fcvt(doublevalue,intndigit,int*decpt,int*sign);
程序例:
#include
#include
#include
intmain(void)
{
char*string;
doublevalue;
intdec,sign;
intndig=10;
clrscr();
value=9.876;
string=ecvt(value,ndig,&dec,&sign);
printf("string=%s dec=%d\
sign=%d\n",string,dec,sign);
value=-123.45;
ndig=15;
string=ecvt(value,ndig,&dec,&sign);
printf("string=%sdec=%dsign=%d\n",
string,dec,sign);
value=0.6789e5;/*scientific
notation*/
ndig=5;
string=ecvt(value,ndig,&dec,&sign);
printf("string=%s dec=%d\
sign=%d\n",string,dec,sign);
return0;
}
函数名:
fdopen
功 能:
把流与一个文件句柄相接
用 法:
FILE*fdopen(inthandle,char*type);
程序例:
#include
#include
#include
#include
intmain(void)
{
inthandle;
FILE*stream;
/*openafile*/
handle=open("DUMMY.FIL",O_CREAT,
S_IREAD|S_IWRITE);
/*nowturnthehandleintoastream*/
stream=fdopen(handle,"w");
if(stream==NULL)
printf("fdopenfailed\n");
else
{
fprintf(stream,"Helloworld\n");
fclose(stream);
}
return0;
}
函数名:
filelength
功 能:
取文件长度字节数
用 法:
longfilelength(inthandle);
程序例:
#include
#include
#include
#include
intmain(void)
{
inthandle;
charbuf[11]="0123456789";
/*createafilecontaining10bytes*/
handle=open("DUMMY.FIL",O_CREAT);
write(handle,buf,strlen(buf));
/*displaythesizeofthefile*/
printf("filelengthinbytes:
%ld\n",
filelength(handle));
/*closethefile*/
close(handle);
return0;
}
函数名:
fillellipse
功 能:
画出并填充一椭圆
用 法:
voidfarfillellipse(intx,inty,intxradius,intyradius);
程序例:
#include
#include
intmain(void)
{
intgdriver=DETECT,gmode;
intxcenter,ycenter,i;
initgraph(&gdriver,&gmode,"");
xcenter=getmaxx()/2;
ycenter=getmaxy()/2;
for(i=0;i<13;i++)
{
setfillstyle(i,WHITE);
fillellipse(xcenter,ycenter,100,50);
getch();
}
closegraph();
return0;
}
函数名:
fillpoly
功 能:
画并填充一个多边形
用 法:
voidfarfillpoly(intnumpoints,intfar*polypoints);
程序例:
#include
#include
#include
#include
intmain(void)
{
/*requestautodetection*/
intgdriver=DETECT,gmode,errorcode;
inti,maxx,maxy;
/*ourpolygonarray*/
intpoly[8];
/*initializegraphics,localvariables*/
initgraph(&gdriver,&gmode,"");
/*readresultofinitialization*/
errorcode=graphresult();
if(errorcode!
=grOk)
/*anerroroccurred*/
{
printf("Graphicserror:
%s\n",
grapherrormsg(errorcode));
printf("Pressanykeytohalt:
");
getch();
exit
(1);
/*terminatewithanerrorcode*/
}
maxx=getmaxx();
maxy=getmaxy();
poly[0]=20; /*1stvertext*/
poly[1]=maxy/2;
poly[2]=maxx-20;/*2nd*/
poly[3]=20;
poly[4]=maxx-50;/*3rd*/
poly[5]=maxy-20;
/*
4thvertex.fillpolyautomatically
closesthepolygon.
*/
poly[6]=maxx/2;
poly[7]=maxy/2;
/*loopthroughthefillpatterns*/
for(i=EMPTY_FILL;i {
/*setfillpattern*/
setfillstyle(i,getmaxcolor());
/*drawafilledpolygon*/
fillpoly(4,poly);
getch();
}
/*cleanup*/
closegraph();
return0;
}
函数名:
findfirst,findnext
功 能:
搜索磁盘目录;取得下一个匹配的findfirst模式的文件
用 法:
intfindfirst(char*pathname,structffblk*ffblk,intattrib);
intfindnext(structffblk*ffblk);
程序例:
/*findnextexample*/
#include
#include
intmain(void)
{
structffblkffblk;
intdone;
printf("Directorylistingof*.*\n");
done=findfirst("*.*",&ffblk,0);
while(!
done)
{
printf(" %s\n",ffblk.ff_name);
done=findnext(&ffblk);
}
return0;
}
函数名:
floodfill
功 能:
填充一个有界区域
用 法:
voidfarfloodfill(intx,inty,intborder);
程序例:
#include
#include
#include
#include
intmain(void)
{
/*requestautodetection*/
intgdriver=DETECT,gmode,errorcode;
intmaxx,maxy;
/*initializegraphics,localvariables*/
initgraph(&gdriver,&gmode,"");
/*readresultofinitialization*/
errorcode=graphresult();
if(errorcode!
=grOk)
/*anerroroccurred*/
{
printf("Graphicserror:
%s\n",
grapherrormsg(errorcode));
printf("Pressanykeytohalt:
");
getch();
exit
(1);
/*terminatewithanerrorcode*/
}
maxx=getmaxx();
maxy=getmaxy();
/*selectdrawingcolor*/
setcolor(getmaxcolor());
/*selectfillcolor*/
setfillstyle(SOLID_FILL,getmaxcolor());
/*drawaborderaroundthescreen*/
rectangle(0,0,maxx,maxy);
/*drawsomecircles*/
circle(maxx/3,maxy/2,50);
circle(maxx/2,20,100);
circle(maxx-20,maxy-50,75);
circle(20,maxy-20,25);
/*waitforakey*/
getch();
/*fillinboundedregion*/
floodfill(2,2,getmaxcolor());
/*cleanup*/
getch();
closegraph();
return0;
}
函数名:
flushall
功 能:
清除所有缓冲区
用 法:
intflushall(void);
程序例:
#include
intmain(void)
{
FILE*stream;
/*createafile*/
stream=fopen("DUMMY.FIL","w");
/*flushallopenstreams*/
printf("%dstreamswereflushed.\n",
flushall());
/*closethefile*/
fclose(stream);
return0;
}
函数名:
fmod
功 能:
计算x对y的模,即x/y的余数
用 法:
doublefmod(doublex,doubley);
程序例:
#include
#include
intmain(void)
{
doublex=5.0,y=2.0;
doubleresult;
result=fmod(x,y);
printf("Theremainderof(%lf/%lf)is\
%lf\n",x,y,result);
return0;
}
函数名:
fnmerge
功 能:
建立新文件名
用 法:
voidfnerge(char*path,char*drive,char*dir);
程序例:
#include
#include
#include
intmain(void)
{
chars[MAXPATH];
chardrive[MAXDRIVE];
chardir[MAXDIR];
charfile[MAXFILE];
charext[MAXEXT];
getcwd(s,MAXPATH); /*getthecurrentworkingdirectory*/
strcat(s,"\\"); /*appendonatrailing\character*/
fnsplit(s,drive,dir,file,ext);/*splitthestringtoseparateelems*/
strcpy(file,"DATA");
strcpy(ext,".TXT");
fnmerge(s,drive,dir,file,ext); /