This blog is under construction

Saturday 14 September 2013

textheight example in c

Header file:
    graphics.h

Synopsis:
      int textheight(char *string);
     
Description:
     textheight() returns the height of the given text in pixels.


textheight function in c graphics



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

  int main() {
        /* request auto detction */
        int gd = DETECT, gmode;
        int err, ht, x, y;
        char str[32];
        
        /* initialize graphic driver and mode */
        initgraph(&gd, &gmode, "C:/TURBOC3/BGI/");
        
        err = graphresult();
        
        /* error occurred */
        if (err != grOk) {
                printf("Error in graphics: %s\n",
                                        grapherrormsg(err));
                getch();
                return 0;
        }                               
        
        x = y = 25;
        
        strcpy(str, "Hello World!!");
        
        /* outputs the given string at (x, y) */
        outtextxy(x, y, str);
        
        /* returns height of the given text in pixels */
        ht = textheight(str);
        
        /* outputs the given string at (x, y + ht) */
        outtextxy(x, y + ht, str);

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





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


No comments:

Post a Comment