User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

Q&A is closed



Syntax of settextjustify

#include <graphics.h>
void settextjustify(int horiz, int vert);

Description of settextjustify

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 of settextjustify ==== 
<code c>  Name  Value  Action
horiz       LEFT_TEXT   0  left-justify text
   CENTER_TEXT 1  center text
   RIGHT_TEXT  2  right-justify text
vertical    BOTTOM_TEXT 0  bottom-justify text
   CENTER_TEXT 1  center text
   TOP_TEXT    2  top-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
settextjustify affects text written with outtext and cannot be used with
text mode and stream functions.

Example of settextjustify

/* 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);

See also

output of settextjustify example

  no output of example at the moment
  do not hesitate and add it...  
c/graphics.h/settextjustify.txt · Last modified: 2015/05/06 23:06 (external edit)

Impressum Datenschutz