This blog is under construction

Saturday, 14 September 2013

textwidth example in c

Header file:
    graphics.h

Synopsis:
      void textwidth(char *string);
     
Description:
     textwidth() returns width of the given input string in pixels.


textwidth function in c graphics



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

  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;
        int err, x = 0, y = 0;
        char str[32];

        /* initialize graphics and local variables */
        initgraph(&graphicDriver, &graphicMode,
                                        "C:/TURBOC3/BGI");

        /* read result of initialization */
        err = graphresult();

        if (err != grOk) {
                /* an error occurred */
                printf("Graphic Error: %s",
                                grapherrormsg(err));
                getch();
                return 0;
        }

        /* moves CP to (10, 10) */
        moveto(10, 10);

        /* get x and y coordiante positions */
        x = getx();
        y = gety();

        /* store the (x, y) positions in a string */
        sprintf(str, "(x, y)=>(%d, %d) ", x, y);

        /* outputs string at (x, y) */
        outtextxy(x, y, str);

        /* find the width of the input string in pixels */
        x = x + textwidth(str);
        outtextxy(x, y, "How Are You?");

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

  }





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


No comments:

Post a Comment