#include <graphics.h>

void settextjustify(int horiz, int vert);

Text output after a call to settextjustify is justified around the current position (CP) horizontally and vertically, as specified. The default justification settings are LEFT_TEXT (for horizontal) and TOP_TEXT (for vertical). The enumeration text_just in graphics.h provides names for the horiz and vert settings passed to settextjustify.
Description   NameValue   Action
horiz   LEFT_TEXT0left-justify text
CENTER_TEXT1center text
RIGHT_TEXT2right-justify text
vertical   BOTTOM_TEXT0bottom-justify text
CENTER_TEXT1center text
TOP_TEXT2top-justify text
If horiz is equal to LEFT_TEXT and direction equals HORIZ_DIR, the CP's x component is advanced after a call to outtext(string) by textwidth(string).

settextjustify affects text written with outtext and cannot be used with text mode and stream functions.

Return Value
If invalid input is passed to settextjustify, graphresult returns -11, and the current text justification remains unchanged.

See also


/* settextjustify example */ 

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

/* function prototype */

void xat(int x, int y);

/* horizontal text justification settings */

char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" };

/* vertical text justification settings */

char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" };

int main(void)


   /* request autodetection */

   int gdriver = DETECT, gmode, errorcode;

   int midx, midy, hj, vj;

   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:");


      exit(1);               /* terminate with an error code */


   midx = getmaxx() / 2;

   midy = getmaxy() / 2;

   /* loop through text justifications */

   for (hj=LEFT_TEXT; hj<=RIGHT_TEXT; hj++)

      for (vj=LEFT_TEXT; vj<=RIGHT_TEXT; vj++) {


         /* set the text justification */

         settextjustify(hj, vj);

         /* create a message string */

         sprintf(msg, "%s  %s", hjust[hj], vjust[vj]);

         /* create crosshairs on the screen */

         xat(midx, midy);

         /* output the message */

         outtextxy(midx, midy, msg);



   /* clean up */


   return 0;


void xat(int x, int y)       /* draw an x at (x,y) */


  line(x-4, y, x+4, y);

  line(x, y-4, x, y+4);


Back to index