C语言函数大全g开头.docx
- 文档编号:14430714
- 上传时间:2023-06-23
- 格式:DOCX
- 页数:62
- 大小:25.92KB
C语言函数大全g开头.docx
《C语言函数大全g开头.docx》由会员分享,可在线阅读,更多相关《C语言函数大全g开头.docx(62页珍藏版)》请在冰点文库上搜索。
C语言函数大全g开头
函数大全(g开头)
61
函数名:
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++)
{
printf("colors[%d]=%d\n",i,
pal->colors[i]);
getch();
}
/*cleanup*/
getch();
closegraph();
return0;
}
函数名:
getdisk
功能:
取当前磁盘驱动器号
用法:
intgetdisk(void);
程序例:
#include
#include
intmain(void)
{
intdisk;
disk=getdisk()+'A';
printf("Thecurrentdriveis:
%c\n",
disk);
return0;
}
函数名:
getdrivername
功能:
返回指向包含当前图形驱动程序名字的字符串指针
用法:
char*getdrivename(void);
程序例:
#include
#include
#include
#include
intmain(void)
{
/*requestautodetection*/
intgdriver=DETECT,gmode,errorcode;
/*storesthe
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 函数 大全 开头