C语言函数大全G篇.docx

上传人:b****7 文档编号:10551108 上传时间:2023-02-21 格式:DOCX 页数:56 大小:25.68KB
下载 相关 举报
C语言函数大全G篇.docx_第1页
第1页 / 共56页
C语言函数大全G篇.docx_第2页
第2页 / 共56页
C语言函数大全G篇.docx_第3页
第3页 / 共56页
C语言函数大全G篇.docx_第4页
第4页 / 共56页
C语言函数大全G篇.docx_第5页
第5页 / 共56页
点击查看更多>>
下载资源
资源描述

C语言函数大全G篇.docx

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

C语言函数大全G篇.docx

C语言函数大全G篇

G:

函数名:

gcvt

功 能:

把浮点数转换成字符串

用 法:

char*gcvt(doublevalue,intndigit,char*buf);

程序例:

#include

#include

intmain(void)

{

  charstr[25];

  doublenum;

  intsig=5;/*significantdigits*/

  /*aregularnumber*/

  num=9.876;

  gcvt(num,sig,str);

  printf("string=%s\n",str);

  /*anegativenumber*/

  num=-123.4567;

  gcvt(num,sig,str);

  printf("string=%s\n",str);

  /*scientificnotation*/

  num=0.678e5;

  gcvt(num,sig,str);

  printf("string=%s\n",str);

  return(0);

}

函数名:

geninterrupt

功 能:

产生一个软中断

用 法:

voidgeninterrupt(intintr_num);

程序例:

#include

#include

/*functionprototype*/

voidwritechar(charch);

intmain(void)

{

  clrscr();

  gotoxy(80,25);

  writechar('*');

  getch();

  return0;

}

/*

  outputsacharacteratthecurrentcursor

  positionusingthevideoBIOStoavoidthe

  scrollingofthescreenwhenwritingto

  location(80,25).

*/

voidwritechar(charch)

{

  structtext_infoti;

  /*grabcurrenttextsettings*/

  gettextinfo(&ti);

  /*interrupt0x10sub-function9*/

  _AH=9;

  /*charactertobeoutput*/

  _AL=ch;

  _BH=0;                 /*videopage*/

  _BL=ti.attribute; /*videoattribute*/

  _CX=1;          /*repetitionfactor*/

  geninterrupt(0x10); /*outputthechar*/

}

函数名:

getarccoords

功 能:

取得最后一次调用arc的坐标

用 法:

voidfargetarccoords(structarccoordstypefar*arccoords);

程序例:

#include

#include

#include

#include

intmain(void)

{

/*requestautodetection*/

  intgdriver=DETECT,gmode,errorcode;

  structarccoordstypearcinfo;

  intmidx,midy;

  intstangle=45,endangle=270;

  charsstr[80],estr[80];

/*initializegraphicsandlocalvariables*/

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

/*readresultofinitialization*/

  errorcode=graphresult();

/*anerroroccurred*/

  if(errorcode!

=grOk)

  {

     printf("Graphicserror:

%s\n",

            grapherrormsg(errorcode));

     printf("Pressanykeytohalt:

");

     getch();

/*terminatewithanerrorcode*/

     exit

(1);

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

/*drawarcandgetcoordinates*/

  setcolor(getmaxcolor());

  arc(midx,midy,stangle,endangle,100);

  getarccoords(&arcinfo);

/*convertarcinformationintostrings*/

  sprintf(sstr,"*-(%d,%d)",

          arcinfo.xstart,arcinfo.ystart);

  sprintf(estr,"*-(%d,%d)",

          arcinfo.xend,arcinfo.yend);

  /*outputthearcinformation*/

  outtextxy(arcinfo.xstart,

            arcinfo.ystart,sstr);

  outtextxy(arcinfo.xend,

            arcinfo.yend,estr);

  /*cleanup*/

  getch();

  closegraph();

  return0;

}

函数名:

getaspectratio

功 能:

返回当前图形模式的纵横比

用 法:

voidfargetaspectratio(intfar*xasp,intfar*yasp);

程序例:

#include

#include

#include

#include

intmain(void)

{

/*requestautodetection*/

  intgdriver=DETECT,gmode,errorcode;

  intxasp,yasp,midx,midy;

/*initializegraphicsandlocalvariables*/

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

/*readresultofinitialization*/

  errorcode=graphresult();

/*anerroroccurred*/

  if(errorcode!

=grOk)

  {

     printf("Graphicserror:

%s\n",

            grapherrormsg(errorcode));

     printf("Pressanykeytohalt:

");

     getch();

/*terminatewithanerrorcode*/

     exit

(1);

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  setcolor(getmaxcolor());

/*getcurrentaspectratiosettings*/

  getaspectratio(&xasp,&yasp);

/*drawnormalcircle*/

  circle(midx,midy,100);

  getch();

/*drawwidecircle*/

  cleardevice();

  setaspectratio(xasp/2,yasp);

  circle(midx,midy,100);

  getch();

/*drawnarrowcircle*/

  cleardevice();

  setaspectratio(xasp,yasp/2);

  circle(midx,midy,100);

/*cleanup*/

  getch();

  closegraph();

  return0;

}

函数名:

getbkcolor

功 能:

返回当前背景颜色

用 法:

intfargetbkcolor(void);

程序例:

#include

#include

#include

#include

#include

intmain(void)

{

  /*requestautodetection*/

  intgdriver=DETECT,gmode,errorcode;

  intbkcolor,midx,midy;

  charbkname[35];

/*initializegraphicsandlocalvariables*/

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

/*readresultofinitialization*/

  errorcode=graphresult();

/*anerroroccurred*/

  if(errorcode!

=grOk)

  {

     printf("Graphicserror:

%s\n",

            grapherrormsg(errorcode));

     printf("Pressanykeytohalt:

");

     getch();

/*terminatewithanerrorcode*/

     exit

(1);

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  setcolor(getmaxcolor());

/*forcenteringtextonthedisplay*/

  settextjustify(CENTER_TEXT,CENTER_TEXT);

/*getthecurrentbackgroundcolor*/

  bkcolor=getbkcolor();

/*convertcolorvalueintoastring*/

  itoa(bkcolor,bkname,10);

  strcat(bkname,

 "isthecurrentbackgroundcolor.");

/*displayamessage*/

  outtextxy(midx,midy,bkname);

/*cleanup*/

  getch();

  closegraph();

  return0;

}

函数名:

getc

功 能:

从流中取字符

用 法:

intgetc(FILE*stream);

程序例:

#include

intmain(void)

{

  charch;

  printf("Inputacharacter:

");

/*readacharacterfromthe

  standardinputstream*/

  ch=getc(stdin);

  printf("Thecharacterinputwas:

'%c'\n",

         ch);

  return0;

}

 函数名:

getcbrk

功 能:

获取Control_break设置

用 法:

intgetcbrk(void);

程序例:

#include

#include

intmain(void)

{

  if(getcbrk())

     printf("Cntrl-brkflagison\n");

  else

     printf("Cntrl-brkflagisoff\n");

  return0;

}

 函数名:

getch

功 能:

从控制台无回显地取一个字符

用 法:

intgetch(void);

程序例:

#include

#include

intmain(void)

{

  charch;

  printf("Inputacharacter:

");

  ch=getche();

  printf("\nYouinputa'%c'\n",ch);

  return0;

}

函数名:

getchar

功 能:

从stdin流中读字符

用 法:

intgetchar(void);

程序例:

#include

intmain(void)

{

  intc;

  /*Notethatgetcharreadsfromstdinand

     islinebuffered;thismeansitwill

     notreturnuntilyoupressENTER.*/

  while((c=getchar())!

='\n')

     printf("%c",c);

  return0;

}

函数名:

getche

功 能:

从控制台取字符(带回显)

用 法:

intgetche(void);

程序例:

#include

#include

intmain(void)

{

  charch;

  printf("Inputacharacter:

");

  ch=getche();

  printf("\nYouinputa'%c'\n",ch);

  return0;

}

函数名:

getcolor

功 能:

返回当前画线颜色

用 法:

intfargetcolor(void);

程序例:

#include

#include

#include

#include

#include

intmain(void)

{

/*requestautodetection*/

  intgdriver=DETECT,gmode,errorcode;

  intcolor,midx,midy;

  charcolname[35];

/*initializegraphicsandlocalvariables*/

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

/*readresultofinitialization*/

  errorcode=graphresult();

/*anerroroccurred*/

  if(errorcode!

=grOk)

  {

     printf("Graphicserror:

%s\n",

            grapherrormsg(errorcode));

     printf("Pressanykeytohalt:

");

     getch();

/*terminatewithanerrorcode*/

     exit

(1);

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  setcolor(getmaxcolor());

/*forcenteringtextonthedisplay*/

  settextjustify(CENTER_TEXT,CENTER_TEXT);

/*getthecurrentdrawingcolor*/

  color=getcolor();

/*convertcolorvalueintoastring*/

  itoa(color,colname,10);

  strcat(colname,

  "isthecurrentdrawingcolor.");

/*displayamessage*/

  outtextxy(midx,midy,colname);

/*cleanup*/

  getch();

  closegraph();

  return0;

}

函数名:

getcurdir

功 能:

取指定驱动器的当前目录

用 法:

intgetcurdir(intdrive,char*direc);

程序例:

#include

#include

#include

char*current_directory(char*path)

{

  strcpy(path,"X:

\\");     /*fillstringwithformofresponse:

X:

\*/

  path[0]='A'+getdisk();   /*replaceXwithcurrentdriveletter*/

  getcurdir(0,path+3); /*fillrestofstringwithcurrentdirectory*/

  return(path);

}

intmain(void)

{

  charcurdir[MAXPATH];

  current_directory(curdir);

  printf("Thecurrentdirectoryis%s\n",curdir);

  return0;

}

 函数名:

getcwd

功 能:

取当前工作目录

用 法:

char*getcwd(char*buf,intn);

程序例:

#include

#include

intmain(void)

{

  charbuffer[MAXPATH];

  getcwd(buffer,MAXPATH);

  printf("Thecurrentdirectoryis:

%s\n",buffer);

  return0;

}

 函数名:

getdate

功 能:

取DOS日期

用 法:

voidgetdate(struct*dateblk);

程序例:

#include

#include

intmain(void)

{

  structdated;

  getdate(&d);

  printf("Thecurrentyearis:

%d\n",

  d.da_year);

  printf("Thecurrentdayis:

%d\n",

  d.da_day);

  printf("Thecurrentmonthis:

%d\n",

  d.da_mon);

  return0;

}

 函数名:

getdefaultpalette

功 能:

返回调色板定义结构

用 法:

structpalettetype*fargetdefaultpalette(void);

程序例:

#include

#include

#include

#include

intmain(void)

{

/*requestautodetection*/

  intgdriver=DETECT,gmode,errorcode;

  inti;

/*structureforreturningpalettecopy*/

  structpalettetypefar*pal=(void*)0;

/*initializegraphicsandlocalvariables*/

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

/*readresultofinitialization*/

  errorcode=graphresult();

/*anerroroccurred*/

  if(errorcode!

=grOk)

  {

     printf("Graphicserror:

%s\n",

            grapherrormsg(errorcode));

     printf("Pressanykeytohalt:

");

     getch();

/*terminatewithanerrorcode*/

     exit

(1);

  }

  setcolor(getmaxcolor());

/*returnapointertothedefaultpalette*/

  pal=getdefaultpalette();

  for(i=0;i<16;i++

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

当前位置:首页 > 求职职场 > 笔试

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

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