C語言函式(G類字母-5)是一個程式語言函式,功能是返回當前圖形位置的y坐標。
基本介紹
- 中文名:C語言函式(G類字母-5)
- 函式名::gety
- 功 能:返回當前圖形位置的y坐標
- 用 法: int far gety(void);
基本信息,程式舉例,
基本信息
函式名: gety
功 能: 返回當前圖形位置的y坐標
用 法: int far gety(void);
程式舉例
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
char msg[80];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
/* move to the screen center point */
moveto(getmaxx() / 2, getmaxy() / 2);
/* create a message string */
sprintf(msg, "<-(%d, %d) is the here.", getx(), gety());
/* display the message */
outtext(msg);
/* clean up */
getch();
closegraph();
return 0;
}
函式名: gmtime
功 能: 把日期和時間轉換為格林尼治標準時間(GMT)
用 法: struct tm *gmtime(long *clock);
程式例:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
/* Pacific Standard Time & Daylight Savings */
char *tzstr = "TZ=PST8PDT";
int main(void)
{
time_t t;
struct tm *gmt, *area;
putenv(tzstr);
tzset();
t = time(NULL);
area = localtime(&t);
printf("Local time is: %s", asctime(area));
gmt = gmtime(&t);
printf("GMT is: %s", asctime(gmt));
return 0;
}
函式名: gotoxy
功 能: 在文本視窗中設定游標
用 法: void gotoxy(int x, int y);
程式例:
#include <conio.h>
int main(void)
{
clrscr();
gotoxy(35, 12);
cprintf("Hello world");
getch();
return 0;
}
函式名: gotoxy
功 能: 在文本視窗中設定游標
用 法: void gotoxy(int x, int y);
程式例:
#include <conio.h>
int main(void)
{
clrscr();
gotoxy(35, 12);
cprintf("Hello world");
getch();
return 0;
}
函式名: graphdefaults
功 能: 將所有圖形設定復位為它們的預設值
用 法: void far graphdefaults(void);
程式例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\\bor\\Borland\\bgi");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
maxx = getmaxx();
maxy = getmaxy();
/* output line with non-default settings */
setlinestyle(DOTTED_LINE, 0, 3);
line(0, 0, maxx, maxy);
outtextxy(maxx/2, maxy/3, "Before default values are restored.");
getch();
/* restore default values for everything */
/* clear the screen */
cleardevice();
/* output line with default settings */
line(0, 0, maxx, maxy);
outtextxy(maxx/2, maxy/3, "After restoring default values.");
/* clean up */
getch();
closegraph();
return 0;
}
函式名: grapherrormsg
功 能: 返回一個錯誤信息串的指針
用 法: char *far grapherrormsg(int errorcode);
程式例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define NONSENSE -50
int main(void)
{
/* FORCE AN ERROR TO OCCUR */
int gdriver = NONSENSE, gmode, errorcode;
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
/* if an error occurred, then output a */
/* descriptive error message. */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
/* draw a line */
line(0, 0, getmaxx(), getmaxy());
/* clean up */
getch();
closegraph();
return 0;
}
函式名: graphresult
功 能: 返回最後一次不成功的圖形操作的錯誤代碼
用 法: int far graphresult(void);
程式例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
/* draw a line */
line(0, 0, getmaxx(), getmaxy());
/* clean up */
getch();
closegraph();
return 0;
}
函式名: _graphfreemem
功 能: 用戶可修改的圖形存儲區釋放函式
用 法: void far _graphfreemem(void far *ptr, unsigned size);
程式例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
/* clear the text screen */
clrscr();
printf("Press any key to initialize graphics mode:");
getch();
clrscr();
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
/* display a message */
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(midx, midy, "Press any key to exit graphics mode:");
/* clean up */
getch();
closegraph();
return 0;
}
/* called by the graphics kernel to allocate memory */
void far * far _graphgetmem(unsigned size)
{
printf("_graphgetmem called to allocate %d bytes.\n", size);
printf("hit any key:");
getch();
printf("\n");
/* allocate memory from far heap */
return farmalloc(size);
}
/* called by the graphics kernel to free memory */
void far _graphfreemem(void far *ptr, unsigned size)
{
printf("_graphfreemem called to free %d bytes.\n", size);
printf("hit any key:");
getch();
printf("\n");
/* free ptr from far heap */
farfree(ptr);
}