Header file:
graphics.h
Synopsis:
void outtextxy (int x, int y, char *textstring);
Description:
outtextxy() prints the given text at the given position(x, y).
outtextxy function in c graphics
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
int main(void) {
/* request auto detection */
int graphicDriver = DETECT, graphicMode;
int i, dir, err, midx, midy;
char str[80];
/* initialize graphics and local variables */
initgraph(&graphicDriver, &graphicMode, "C:/TURBOC3/BGI");
/* read result of initialization */
err = graphresult();
if (err != grOk) {
/* error occurred */
printf("Graphic Error: %s\n",
grapherrormsg(err));
return 0;
}
/* mid position in x and y-axis */
midx = getmaxx() / 2;
midy = getmaxy() / 2;
for (i = 1; i <= 15; i++) {
/* clears graphic screen */
cleardevice();
/* setting the current drawing color */
setcolor(i);
/* sets the current text style */
dir = (i % 2) == 0 ? HORIZ_DIR : VERT_DIR;
settextstyle(TRIPLEX_FONT, dir, 3);
/* sets text justification */
settextjustify(CENTER_TEXT, CENTER_TEXT);
sprintf(str, "Color code is %d", i);
/* prints the given string */
outtextxy(midx, midy, str);
getch();
}
/* clean up */
getch();
closegraph();
return 0;
}
Output: (outtextxy built-in function in c graphics.h)
No comments:
Post a Comment