This blog is under construction

Thursday, 12 September 2013

outtext example in c

Header file:
    graphics.h

Synopsis:
      void outtext (char *textstring);
     
Description:
     outtext() prints the given string at the current position in graphic screen.


outtext function in c graphics



  #include <graphics.h>
  #include <stdlib.h>
  #include <stdio.h>
  #include <string.h>
  #include <conio.h>

  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;
        int i, 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));
                getch();
                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 */
                settextstyle(TRIPLEX_FONT, HORIZ_DIR, 3);

                /* sets text justification */
                settextjustify(CENTER_TEXT, CENTER_TEXT);

                sprintf(str, "Color code is %d", i);

                /* move to center position of current graphic screen */
                moveto(midx, midy);

                /* prints the given string */
                outtext(str);
                getch();
        }

        /* clean up */
        getch();
        closegraph();
        return 0;
  }





Output: (outtext built-in function in c graphics.h)


No comments:

Post a Comment