C语言函数大全2.docx

上传人:b****3 文档编号:5471421 上传时间:2023-05-08 格式:DOCX 页数:96 大小:34.26KB
下载 相关 举报
C语言函数大全2.docx_第1页
第1页 / 共96页
C语言函数大全2.docx_第2页
第2页 / 共96页
C语言函数大全2.docx_第3页
第3页 / 共96页
C语言函数大全2.docx_第4页
第4页 / 共96页
C语言函数大全2.docx_第5页
第5页 / 共96页
C语言函数大全2.docx_第6页
第6页 / 共96页
C语言函数大全2.docx_第7页
第7页 / 共96页
C语言函数大全2.docx_第8页
第8页 / 共96页
C语言函数大全2.docx_第9页
第9页 / 共96页
C语言函数大全2.docx_第10页
第10页 / 共96页
C语言函数大全2.docx_第11页
第11页 / 共96页
C语言函数大全2.docx_第12页
第12页 / 共96页
C语言函数大全2.docx_第13页
第13页 / 共96页
C语言函数大全2.docx_第14页
第14页 / 共96页
C语言函数大全2.docx_第15页
第15页 / 共96页
C语言函数大全2.docx_第16页
第16页 / 共96页
C语言函数大全2.docx_第17页
第17页 / 共96页
C语言函数大全2.docx_第18页
第18页 / 共96页
C语言函数大全2.docx_第19页
第19页 / 共96页
C语言函数大全2.docx_第20页
第20页 / 共96页
亲,该文档总共96页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

C语言函数大全2.docx

《C语言函数大全2.docx》由会员分享,可在线阅读,更多相关《C语言函数大全2.docx(96页珍藏版)》请在冰点文库上搜索。

C语言函数大全2.docx

C语言函数大全2

返回>>C语言函数大全

函数名:

ecvt

功 能:

把一个浮点数转换为字符串

用 法:

charecvt(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;

}

 

 

函数名:

ellipse

功 能:

画一椭圆

用 法:

voidfarellipse(intx,inty,intstangle,intendangle,

   intxradius,intyradius);

程序例:

#include

#include

#include

#include

intmain(void)

{

  /*requestautodetection*/

  intgdriver=DETECT,gmode,errorcode;

  intmidx,midy;

  intstangle=0,endangle=360;

  intxradius=100,yradius=50;

  /*initializegraphics,localvariables*/

  initgraph(&gdriver,&gmode,"");

  /*readresultofinitialization*/

  errorcode=graphresult();

  if(errorcode!

=grOk)

  /*anerroroccurred*/

  {

     printf("Graphicserror:

%s\n",

     grapherrormsg(errorcode));

     printf("Pressanykeytohalt:

");

     getch();

     exit

(1);

  /*terminatewithanerrorcode*/

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  setcolor(getmaxcolor());

  /*drawellipse*/

  ellipse(midx,midy,stangle,endangle,

   xradius,yradius);

  /*cleanup*/

  getch();

  closegraph();

  return0;

}

 

 

函数名:

enable

功 能:

开放硬件中断

用 法:

voidenable(void);

程序例:

/***NOTE:

Thisisaninterruptserviceroutine.YoucanNOTcompilethisprogram

withTestStackOverflowturnedonandgetanexecutablefilewhichwill

operatecorrectly.

*/

#include

#include

#include

/*Theclocktickinterrupt*/

#defineINTR0X1C

voidinterrupt(*oldhandler)(void);

intcount=0;

voidinterrupthandler(void)

{

/*

  disableinterruptsduringthehandlingoftheinterrupt

*/

  disable();

/*increasetheglobalcounter*/

  count++;

/*

  reenableinterruptsattheendofthehandler

*/

  enable();

/*calltheoldroutine*/

  oldhandler();

}

intmain(void)

{

/*savetheoldinterruptvector*/

  oldhandler=getvect(INTR);

/*installthenewinterrupthandler*/

  setvect(INTR,handler);

/*loopuntilthecounterexceeds20*/

  while(count<20)

     printf("countis%d\n",count);

/*resettheoldinterrupthandler*/

  setvect(INTR,oldhandler);

  return0;

}

 

 

函数名:

eof

功 能:

检测文件结束

用 法:

inteof(int*handle);

程序例:

#include

#include

#include

#include

#include

intmain(void)

{

  inthandle;

  charmsg[]="Thisisatest";

  charch;

  /*createafile*/

  handle=open("DUMMY.FIL",

  O_CREAT|O_RDWR,

  S_IREAD|S_IWRITE);

  /*writesomedatatothefile*/

  write(handle,msg,strlen(msg));

  /*seektothebeginningofthefile*/

  lseek(handle,0L,SEEK_SET);

  /*

     readscharsfromthefileuntilhitEOF

  */

  do

  {

     read(handle,&ch,1);

     printf("%c",ch);

  }while(!

eof(handle));

  close(handle);

  return0;

}

 

 

函数名:

exec...

功 能:

装入并运行其它程序的函数

用 法:

intexecl(char*pathname,char*arg0,arg1,...,argn,NULL);

 intexecle(char*pathname,char*arg0,arg1,...,argn,NULL,

    char*envp[]);

 intexeclp(char*pathname,char*arg0,arg1,..,NULL);

 intexecple(char*pathname,char*arg0,arg1,...,NULL,

     char*envp[]);

 intexecv(char*pathname,char*argv[]);

 intexecve(char*pathname,char*argv[],char*envp[]);

 intexecvp(char*pathname,char*argv[]);

 intexecvpe(char*pathname,char*argv[],char*envp[]);

程序例:

/*execvexample*/

#include

#include

#include

voidmain(intargc,char*argv[])

{

  inti;

  printf("Commandlinearguments:

\n");

  for(i=0;i

     printf("[%2d]:

%s\n",i,argv[i]);

  printf("Abouttoexecchildwitharg1arg2...\n");

  execv("CHILD.EXE",argv);

  perror("execerror");

  exit

(1);

}

 

 

函数名:

exit

功 能:

终止程序

用 法:

voidexit(intstatus);

程序例:

#include

#include

#include

intmain(void)

{

  intstatus;

  printf("Entereither1or2\n");

  status=getch();

  /*SetsDOSerrorlevel */

  exit(status-'0');

/*Note:

thislineisneverreached*/

  return0;

}

 

 

函数名:

exp

功 能:

指数函数

用 法:

doubleexp(doublex);

程序例:

#include

#include

intmain(void)

{

  doubleresult;

  doublex=4.0;

  result=exp(x);

  printf("'e'raisedtothepower\

  of%lf(e^%lf)=%lf\n",

  x,x,result);

  return0;

}

返回>>C语言函数大全

函数名:

fabs

功 能:

返回浮点数的绝对值

用 法:

doublefabs(doublex);

程序例:

#include

#include

intmain(void)

{

  float number=-1234.0;

  printf("number:

%f absolutevalue:

%f\n",

  number,fabs(number));

  return0;

}

 

 

 

函数名:

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;

}

 

 

函数名:

fclose

功 能:

关闭一个流

用 法:

intfclose(FILE*stream);

程序例:

#include

#include

intmain(void)

{

  FILE*fp;

  charbuf[11]="0123456789";

  /*createafilecontaining10bytes*/

  fp=fopen("DUMMY.FIL","w");

  fwrite(&buf,strlen(buf),1,fp);

  /*closethefile*/

  fclose(fp);

  return0;

}

 

 

 

函数名:

fcloseall

功 能:

关闭打开流

用 法:

intfcloseall(void);

程序例:

#include

intmain(void)

{

  intstreams_closed;

  /*opentwostreams*/

  fopen("DUMMY.ONE","w");

  fopen("DUMMY.TWO","w");

  /*closetheopenstreams*/

  streams_closed=fcloseall();

  if(streams_closed==EOF)

     /*issueanerrormessage*/

     perror("Error");

  else

     /*printresultoffcloseall()function*/

     printf("%dstreamswereclosed.\n",streams_closed);

  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",

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2