分享
 
 
 

C语言库函数(G类字母)

王朝c/c++·作者佚名  2008-06-01
窄屏简体版  字體: |||超大  

函数名: gcvt

功 能: 把浮点数转换成字符串

用 法: char *gcvt(double value, int ndigit, char *buf);

程序例:

#include <stdlib.h>

#include <stdio.h>

int main(void)

{

char str[25];

double num;

int sig = 5; /* significant digits */

/* a regular number */

num = 9.876;

gcvt(num, sig, str);

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

/* a negative number */

num = -123.4567;

gcvt(num, sig, str);

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

/* scientific notation */

num = 0.678e5;

gcvt(num, sig, str);

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

return(0);

}

函数名: geninterrupt

功 能: 产生一个软中断

用 法: void geninterrupt(int intr_num);

程序例:

#include <conio.h>

#include <dos.h>

/* function prototype */

void writechar(char ch);

int main(void)

{

clrscr();

gotoxy(80,25);

writechar('*');

getch();

return 0;

}

/*

outputs a character at the current cursor

position using the video BIOS to avoid the

scrolling of the screen when writing to

location (80,25).

*/

void writechar(char ch)

{

strUCt text_info ti;

/* grab current text settings */

gettextinfo(&ti);

/* interrupt 0x10 sub-function 9 */

_AH = 9;

/* character to be output */

_AL = ch;

_BH = 0; /* video page */

_BL = ti.attribute; /* video attribute */

_CX = 1; /* repetition factor */

geninterrupt(0x10); /* output the char */

}

函数名: getarccoords

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

用 法: void far getarccoords(struct arccoordstype far *arccoords);

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

struct arccoordstype arcinfo;

int midx, midy;

int stangle = 45, endangle = 270;

char sstr[80], estr[80];

/* initialize graphics and local variables */

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

/* read result of initialization */

errorcode = graphresult();

/* an error occurred */

if (errorcode != grOk)

{

printf("Graphics error: %s\n",

grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

/* terminate with an error code */

exit(1);

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

/* draw arc and get coordinates */

setcolor(getmaxcolor());

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

getarccoords(&arcinfo);

/* convert arc information into strings */

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

arcinfo.xstart, arcinfo.ystart);

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

arcinfo.xend, arcinfo.yend);

/* output the arc information */

outtextxy(arcinfo.xstart,

arcinfo.ystart, sstr);

outtextxy(arcinfo.xend,

arcinfo.yend, estr);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: getASPectratio

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

用 法: void far getaspectratio(int far *xasp, int far *yasp);

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int xasp, yasp, midx, midy;

/* initialize graphics and local variables */

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

/* read result of initialization */

errorcode = graphresult();

/* an error occurred */

if (errorcode != grOk)

{

printf("Graphics error: %s\n",

grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

/* terminate with an error code */

exit(1);

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

setcolor(getmaxcolor());

/* get current aspect ratio settings */

getaspectratio(&xasp, &yasp);

/* draw normal circle */

circle(midx, midy, 100);

getch();

/* draw wide circle */

cleardevice();

setaspectratio(xasp/2, yasp);

circle(midx, midy, 100);

getch();

/* draw narrow circle */

cleardevice();

setaspectratio(xasp, yasp/2);

circle(midx, midy, 100);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: getbkcolor

功 能: 返回当前背景颜色

用 法: int far getbkcolor(void);

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <string.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int bkcolor, midx, midy;

char bkname[35];

/* initialize graphics and local variables */

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

/* read result of initialization */

errorcode = graphresult();

/* an error occurred */

if (errorcode != grOk)

{

printf("Graphics error: %s\n",

grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

/* terminate with an error code */

exit(1);

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

setcolor(getmaxcolor());

/* for centering text on the display */

settextjustify(CENTER_TEXT, CENTER_TEXT);

/* get the current background color */

bkcolor = getbkcolor();

/* convert color value into a string */

itoa(bkcolor, bkname, 10);

strcat(bkname,

" is the current background color.");

/* display a message */

outtextxy(midx, midy, bkname);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: getc

功 能: 从流中取字符

用 法: int getc(FILE *stream);

程序例:

#include <stdio.h>

int main(void)

{

char ch;

printf("Input a character:");

/* read a character from the

standard input stream */

ch = getc(stdin);

printf("The character input was: '%c'\n",

ch);

return 0;

}

函数名: getcbrk

功 能: 获取Control_break设置

用 法: int getcbrk(void);

程序例:

#include <stdio.h>

#include <dos.h>

int main(void)

{

if (getcbrk())

printf("Cntrl-brk flag is on\n");

else

printf("Cntrl-brk flag is off\n");

return 0;

}

函数名: getch

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

用 法: int getch(void);

程序例:

#include <stdio.h>

#include <conio.h>

int main(void)

{

char ch;

printf("Input a character:");

ch = getche();

printf("\nYou input a '%c'\n", ch);

return 0;

}

函数名: getchar

功 能: 从stdin流中读字符

用 法: int getchar(void);

程序例:

#include <stdio.h>

int main(void)

{

int c;

/* Note that getchar reads from stdin and

is line buffered; this means it will

not return until you press ENTER. */

while ((c = getchar()) != '\n')

printf("%c", c);

return 0;

}

函数名: getche

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

用 法: int getche(void);

程序例:

#include <stdio.h>

#include <conio.h>

int main(void)

{

char ch;

printf("Input a character:");

ch = getche();

printf("\nYou input a '%c'\n", ch);

return 0;

}

函数名: getcolor

功 能: 返回当前画线颜色

用 法: int far getcolor(void);

程序例:

#include <graphics.h>

#include <stdlib.h>

#include <string.h>

#include <stdio.h>

#include <conio.h>

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int color, midx, midy;

char colname[35];

/* initialize graphics and local variables */

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

/* read result of initialization */

errorcode = graphresult();

/* an error occurred */

if (errorcode != grOk)

{

printf("Graphics error: %s\n",

grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

/* terminate with an error code */

exit(1);

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

setcolor(getmaxcolor());

/* for centering text on the display */

settextjustify(CENTER_TEXT, CENTER_TEXT);

/* get the current drawing color */

color = getcolor();

/* convert color value into a string */

itoa(color, colname, 10);

strcat(colname,

" is the current drawing color.");

/* display a message */

outtextxy(midx, midy, colname);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: getcurdir

功 能: 取指定驱动器的当前目录

用 法: int getcurdir(int drive, char *direc);

程序例:

#include <dir.h>

#include <stdio.h>

#include <string.h>

char *current_Directory(char *path)

{

strcpy(path, "X:\\"); /* fill string with form of response: X:\ */

path[0] = 'A' + getdisk(); /* replace X with current drive letter */

getcurdir(0, path+3); /* fill rest of string with current directory */

return(path);

}

int main(void)

{

char curdir[MAXPATH];

current_directory(curdir);

printf("The current directory is %s\n", curdir);

return 0;

}

函数名: getcwd

功 能: 取当前工作目录

用 法: char *getcwd(char *buf, int n);

程序例:

#include <stdio.h>

#include <dir.h>

int main(void)

{

char buffer[MAXPATH];

getcwd(buffer, MAXPATH);

printf("The current directory is: %s\n", buffer);

return 0;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有