You need to clip the output. Wrap outtextxy
like this (you may need to adjust the parameters and return value to match outtextxy
). I am assuming that you are using a fixed-width font.
Clipping text in the x-coordinate would be something similar to this:
int clippedouttext(int x, int y, char *text) {
const int CHAR_WIDTH = 8; /* Replace 8 by actual character width */
if (text == NULL || *text = '\0') { return 0; } /* No text was submitted */
while (x < 0) {
x += CHAR_WIDTH;
++text;
if (*text == `\0`) { return 0; } /* The text is outside the viewport. */
}
return outtextxy(x, y, text);
}