📄 026.htm
字号:
<BR>
<P>函数名: getche
<BR>功 能: 从控制台取字符(带回显)
<BR>用 法: int getche(void);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> char ch;
<BR>
<P> printf("Input a character:");
<BR> ch = getche();
<BR> printf("\nYou input a '%c'\n", ch);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getcolor
<BR>功 能: 返回当前画线颜色
<BR>用 法: int far getcolor(void);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <string.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR>/* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int color, midx, midy;
<BR> char colname[35];
<BR>
<P>/* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P>/* read result of initialization */
<BR> errorcode = graphresult();
<BR>/* an error occurred */
<BR> if (errorcode != grOk)
<BR> {
<BR> printf("Graphics error: %s\n",
<BR>
grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR>/* terminate with an error code */
<BR> exit(1);
<BR> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR> setcolor(getmaxcolor());
<BR>
<P>/* for centering text on the display */
<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR>
<P>/* get the current drawing color */
<BR> color = getcolor();
<BR>
<P>/* convert color value into a string */
<BR> itoa(color, colname, 10);
<BR> strcat(colname,
<BR> " is the current drawing color.");
<BR>
<P>/* display a message */
<BR> outtextxy(midx, midy, colname);
<BR>
<P>/* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getcurdir
<BR>功 能: 取指定驱动器的当前目录
<BR>用 法: int getcurdir(int drive, char *direc);
<BR>程序例:
<BR>
<P>#include <dir.h>
<BR>#include <stdio.h>
<BR>#include <string.h>
<BR>
<P>char *current_directory(char *path)
<BR>{
<BR> strcpy(path, "X:\\"); /*
fill string with form of response: X:\ */
<BR> path[0] = 'A' + getdisk(); /* replace
X with current drive letter */
<BR> getcurdir(0, path+3); /* fill rest of string with
current directory */
<BR> return(path);
<BR>}
<BR>
<P>int main(void)
<BR>{
<BR> char curdir[MAXPATH];
<BR>
<P> current_directory(curdir);
<BR> printf("The current directory is %s\n", curdir);
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getcwd
<BR>功 能: 取当前工作目录
<BR>用 法: char *getcwd(char *buf, int n);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <dir.h>
<BR>
<P>int main(void)
<BR>{
<BR> char buffer[MAXPATH];
<BR>
<P> getcwd(buffer, MAXPATH);
<BR> printf("The current directory is: %s\n", buffer);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getdate
<BR>功 能: 取DOS日期
<BR>用 法: void getdate(struct *dateblk);
<BR>程序例:
<BR>
<P>#include <dos.h>
<BR>#include <stdio.h>
<BR>
<P>int main(void)
<BR>{
<BR> struct date d;
<BR>
<P> getdate(&d);
<BR> printf("The current year is: %d\n",
<BR> d.da_year);
<BR> printf("The current day is: %d\n",
<BR> d.da_day);
<BR> printf("The current month is: %d\n",
<BR> d.da_mon);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getdefaultpalette
<BR>功 能: 返回调色板定义结构
<BR>用 法: struct palettetype *far getdefaultpalette(void);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR>/* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int i;
<BR>
<P>/* structure for returning palette copy */
<BR> struct palettetype far *pal=(void *) 0;
<BR>
<P>/* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P>/* read result of initialization */
<BR> errorcode = graphresult();
<BR>/* an error occurred */
<BR> if (errorcode != grOk)
<BR> {
<BR> printf("Graphics error: %s\n",
<BR>
grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR>/* terminate with an error code */
<BR> exit(1);
<BR> }
<BR>
<P> setcolor(getmaxcolor());
<BR>
<P>/* return a pointer to the default palette */
<BR> pal = getdefaultpalette();
<BR>
<P> for (i=0; i<16; i++)
<BR> {
<BR> printf("colors[%d] = %d\n", i,
<BR>
pal->colors[i]);
<BR> getch();
<BR> }
<BR>
<P>/* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getdisk
<BR>功 能: 取当前磁盘驱动器号
<BR>用 法: int getdisk(void);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <dir.h>
<BR>
<P>int main(void)
<BR>{
<BR> int disk;
<BR>
<P> disk = getdisk() + 'A';
<BR> printf("The current drive is: %c\n",
<BR> disk);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: getdrivername
<BR>功 能: 返回指向包含当前图形驱动程序名字的字符串指针
<BR>用 法: char *getdrivename(void);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR>/* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR>
<P>/* stores the device driver name */
<BR> char *drivername;
<BR>
<P>/* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P>/* read result of initialization */
<BR> errorcode = graphresult();
<BR>/* an error occurred */
<BR> if (errorcode != grOk)
<BR> {
<BR> printf("Graphics error: %s\n",
<BR>
grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR>/* terminate with an error code */
<BR> exit(1);
<BR> }
<BR>
<P> setcolor(getmaxcolor());
<BR>
<P>/* get name of the device driver in use */
<BR> drivername = getdrivername();
<BR>
<P>/* for centering text on the screen */
<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);
<BR>
<P>/* output the name of the driver */
<BR> outtextxy(getmaxx() / 2, getmaxy() / 2,
<BR> drivername);
<BR>
<P>/* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getdta
<BR>功 能: 取磁盘传输地址
<BR>用 法: char far *getdta(void);
<BR>程序例:
<BR>
<P>#include <dos.h>
<BR>#include <stdio.h>
<BR>
<P>int main(void)
<BR>{
<BR> char far *dta;
<BR>
<P> dta = getdta();
<BR> printf("The current disk transfer \
<BR> address is: %Fp\n", dta);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getenv
<BR>功 能: 从环境中取字符串
<BR>用 法: char *getenv(char *envvar);
<BR>程序例:
<BR>
<P>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>
<BR>
<P>int main(void)
<BR>{
<BR> char *s;
<BR>
<P> s=getenv("COMSPEC");
/* get the comspec environment parameter */
<BR> printf("Command processor: %s\n",s);
/* display comspec parameter */
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<BR>
<P>函数名: getfat, getfatd
<BR>功 能: 取文件分配表信息
<BR>用 法: void getfat(int drive, struct fatinfo *fatblkp);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <dos.h>
<BR>
<P>int main(void)
<BR>{
<BR> struct fatinfo diskinfo;
<BR> int flag = 0;
<BR>
<P> printf("Please insert disk in drive A\n");
<BR> getchar();
<BR>
<P> getfat(1, &diskinfo);
<BR>/* get drive information */
<BR>
<P> printf("\nDrive A: is ");
<BR> switch((unsigned char) diskinfo.fi_fatid)
<BR> {
<BR> case 0xFD:
<BR> printf("360K low density\n");
<BR> break;
<BR>
<P> case 0xF9:
<BR> printf("1.2 Meg high density\n");
<BR> break;
<BR>
<P> default:
<BR> printf("unformatted\n");
<BR> flag = 1;
<BR> }
<BR>
<P> if (!flag)
<BR> {
<BR> printf(" sectors per cluster %5d\n",
<BR> diskinfo.fi_sclus);
<BR> printf(" number of clusters
%5d\n",
<BR> diskinfo.fi_nclus);
<BR> printf(" bytes
per sector %5d\n",
<BR> diskinfo.fi_bysec);
<BR> }
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: getfillpattern
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -