C语言D.docx

上传人:b****6 文档编号:4354671 上传时间:2022-11-30 格式:DOCX 页数:10 大小:19.33KB
下载 相关 举报
C语言D.docx_第1页
第1页 / 共10页
C语言D.docx_第2页
第2页 / 共10页
C语言D.docx_第3页
第3页 / 共10页
C语言D.docx_第4页
第4页 / 共10页
C语言D.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

C语言D.docx

《C语言D.docx》由会员分享,可在线阅读,更多相关《C语言D.docx(10页珍藏版)》请在冰豆网上搜索。

C语言D.docx

C语言D

返回>>C语言函数大全

函数名:

delay          

功 能:

将程序的执行暂停一段时间(毫秒)

用 法:

voiddelay(unsignedmilliseconds);

程序例:

/*Emitsa440-Hztonefor500milliseconds*/

#include

intmain(void)

{

  sound(440);

  delay(500);

  nosound();

  return0;

}

 

 

函数名:

delline

功 能:

在文本窗口中删去一行

用 法:

voiddelline(void);

程序例:

#include

intmain(void)

{

  clrscr();

  cprintf("ThefunctionDELLINEdeletes\

   thelinecontainingthe\r\n");

  cprintf("cursorandmovesalllines\

   belowitonelineup.\r\n");

  cprintf("DELLINEoperateswithinthe\

   currentlyactivetext\r\n");

  cprintf("window. Pressanykeyto\

   continue...");

  gotoxy(1,2); /*Movethecursortothe

     secondlineandfirstcolumn*/

  getch();

  delline();

  getch();

  return0;

}

 

函数名:

detectgraph

功 能:

通过检测硬件确定图形驱动程序和模式

用 法:

voidfardetectgraph(intfar*graphdriver,intfar*graphmode);

程序例:

#include

#include

#include

#include

/*namesofthevariouscardssupported*/

char*dname[]={"requestsdetection",

   "aCGA",

   "anMCGA",

   "anEGA",

   "a64KEGA",

   "amonochromeEGA",

   "anIBM8514",

   "aHerculesmonochrome",

   "anAT&T6300PC",

   "aVGA",

   "anIBM3270PC"

 };

intmain(void)

{

  /*returnsdetectedhardwareinfo.*/

  intgdriver,gmode,errorcode;

 /*detectgraphicshardwareavailable*/

  detectgraph(&gdriver,&gmode);

  /*readresultofdetectgraphcall*/

  errorcode=graphresult();

  if(errorcode!

=grOk) /*anerror

        occurred*/

  {

     printf("Graphicserror:

%s\n",\

     grapherrormsg(errorcode));

     printf("Pressanykeytohalt:

");

     getch();

     exit

(1);/*terminatewithanerror

   code*/

  }

  /*displaytheinformationdetected*/

  clrscr();

  printf("Youhave%svideodisplay\

  card.\n",dname[gdriver]);

  printf("Pressanykeytohalt:

");

  getch();

  return0;

}

 

 

 

函数名:

difftime

功 能:

计算两个时刻之间的时间差

用 法:

doubledifftime(time_ttime2,time_ttime1);

程序例:

#include

#include

#include

#include

intmain(void)

{

  time_tfirst,second;

  clrscr();

  first=time(NULL); /*Getssystem

     time*/

  delay(2000);        /*Waits2secs*/

  second=time(NULL);/*Getssystemtime

     again*/

  printf("Thedifferenceis:

%f\

  seconds\n",difftime(second,first));

  getch();

  return0;

}

 

 

函数名:

disable

功 能:

屏蔽中断

用 法:

voiddisable(void);

程序例:

/***NOTE:

Thisisaninterruptservice

 routine.Youcannotcompilethisprogram

 withTestStackOverflowturnedonand

 getanexecutablefilethatoperates

 correctly.*/

#include

#include

#include

#defineINTR0X1C   /*Theclocktick

  interrupt*/

voidinterrupt(*oldhandler)(void);

intcount=0;

voidinterrupthandler(void)

{

/*disableinterruptsduringthehandlingof

  theinterrupt*/

  disable();

/*increasetheglobalcounter*/

  count++;

/*reenableinterruptsattheendofthe

  handler*/

  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;

}

函数名:

div

功 能:

将两个整数相除,返回商和余数

用 法:

div_t(intnumber,intdenom);

程序例:

#include

#include

div_tx;

intmain(void)

{

  x=div(10,3);

  printf("10div3=%dremainder%d\n",x.quot,x.rem);

  return0;

}

 

 

函数名:

dosexterr

功 能:

获取扩展DOS错误信息

用 法:

intdosexterr(structDOSERR*dblkp);

程序例:

#include

#include

intmain(void)

{

  FILE*fp;

  structDOSERRORinfo;

  fp=fopen("perror.dat","r");

  if(!

fp)perror("Unabletoopenfilefor

    reading");

  dosexterr(&info);

  printf("ExtendedDOSerror\

  information:

\n");

  printf("  Extendederror:

\

  %d\n",info.exterror);

  printf("           Class:

\

  %x\n",info.class);

  printf("          Action:

\

  %x\n",info.action);

  printf("     ErrorLocus:

\

  %x\n",info.locus);

  return0;

}

 

 

函数名:

dostounix

功 能:

转换日期和时间为UNIX时间格式

用 法:

longdostounix(structdate*dateptr,structtime*timeptr);

程序例:

 #include

 #include

 #include

 #include

 intmain(void)

 {

   time_tt;

   structtimed_time;

   structdated_date;

   structtm*local;

   getdate(&d_date);

   gettime(&d_time);

   t=dostounix(&d_date,&d_time);

   local=localtime(&t);

   printf("TimeandDate:

%s\n",\

   asctime(local));

   return0;

}

 

 

函数名:

drawpoly

功 能:

画多边形

用 法:

voidfardrawpoly(intnumpoints,intfar*polypoints);

程序例:

#include

#include

#include

#include

intmain(void)

{

  /*requestautodetection*/

  intgdriver=DETECT,gmode,errorcode;

  intmaxx,maxy;

  /*ourpolygonarray*/

  intpoly[10];

  /*initializegraphicsandlocal

     variables*/

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

  /*readresultofinitialization*/

  errorcode=graphresult();

  if(errorcode!

=grOk)

  /*anerroroccurred*/

  {

     printf("Graphicserror:

%s\n",\

     grapherrormsg(errorcode));

     printf("Pressanykeytohalt:

");

     getch();

  /*terminatewithanerrorcode*/

     exit

(1);

  }

  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;

  poly[6]=maxx/2; /*4th*/

  poly[7]=maxy/2;

/*

  drawpolydoesn'tautomaticallyclose

  thepolygon,sowecloseit.

*/

  poly[8]=poly[0];

  poly[9]=poly[1];

  /*drawthepolygon*/

  drawpoly(5,poly);

  /*cleanup*/

  getch();

  closegraph();

  return0;

}

 

 

函数名:

dup

功 能:

复制一个文件句柄

用 法:

intdup(inthandle);

程序例:

#include

#include

#include

#include

voidflush(FILE*stream);

intmain(void)

{

  FILE*fp;

  charmsg[]="Thisisatest";

  /*createafile*/

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

  /*writesomedatatothefile*/

  fwrite(msg,strlen(msg),1,fp);

  clrscr();

  printf("Pressanykeytoflush\

  DUMMY.FIL:

");

  getch();

  /*flushthedatatoDUMMY.FILwithout

     closingit*/

  flush(fp);

  printf("\nFilewasflushed,Pressany\

  keytoquit:

");

  getch();

  return0;

}

voidflush(FILE*stream)

{

  intduphandle;

  /*flushTC'sinternalbuffer*/

  fflush(stream);

  /*makeaduplicatefilehandle*/

  duphandle=dup(fileno(stream));

  /*closetheduplicatehandletoflushthe

     DOSbuffer*/

  close(duphandle);

}

 

 

函数名:

dup2

功 能:

复制文件句柄

用 法:

intdup2(intoldhandle,intnewhandle);

程序例:

#include

#include

#include

#include

intmain(void)

{

  #defineSTDOUT1

  intnul,oldstdout;

  charmsg[]="Thisisatest";

  /*createafile*/

  nul=open("DUMMY.FIL",O_CREAT|O_RDWR,

     S_IREAD|S_IWRITE);

  /*createaduplicatehandleforstandard

     output*/

  oldstdout=dup(STDOUT);

  /*

     redirectstandardoutputtoDUMMY.FIL

     byduplicatingthefilehandleontothe

     filehandleforstandardoutput.

  */

  dup2(nul,STDOUT);

  /*closethehandleforDUMMY.FIL*/

  close(nul);

  /*willberedirectedintoDUMMY.FIL*/

  write(STDOUT,msg,strlen(msg));

  /*restoreoriginalstandardoutput

     handle*/

  dup2(oldstdout,STDOUT);

  /*closeduplicatehandleforSTDOUT*/

  close(oldstdout);

  return0;

}

 

返回C语言首页

©2004-2009 C语言

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

当前位置:首页 > 幼儿教育 > 家庭教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1