How to change the font size in a console application using C

How to change print font size with c?

 printf ("%c", map[x][y]);

I want to print an array more than all the other text in the program. Is there any way to make this conclusion larger?

+5
source share
4 answers

Although teppic answer for use system()will work, quite intensively, to invoke an external program just for that. Regarding the response of David RF , it is hard-coded for a certain type of terminal (perhaps a terminal type with VT100 support) and will not support the actual user terminal type.

In C, you should use the terminfo features directly:

#include <term.h>

/* One-time initialization near the beginning of your program */
setupterm(NULL, STDOUT_FILENO, NULL);

/* Enter bold mode */
putp(enter_bold_mode);

printf("I am bold\n");

/* Turn it off! */
putp(exit_attribute_mode);

, teppic, . .

+4

Linux (, , Unix), system, , , . , , , :

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

[...]

printf("Normal text\n");
system("setterm -bold on");
printf("Bold text\n");
system("setterm -bold off");

, printf, Unix, . \033[31m xterm. .

+1

unix, :

printf("\033[1m%c\033[0m", map[x][y]);
+1

This code will work in Win32 applications (regardless of the subsystem used: WINDOWS or CONSOLE):

inline void setFontSize(int a, int b) 

{

    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

    PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx = new CONSOLE_FONT_INFOEX();

    lpConsoleCurrentFontEx->cbSize = sizeof(CONSOLE_FONT_INFOEX);

    GetCurrentConsoleFontEx(hStdOut, 0, lpConsoleCurrentFontEx);

    lpConsoleCurrentFontEx->dwFontSize.X = a;

    lpConsoleCurrentFontEx->dwFontSize.Y = b;

    SetCurrentConsoleFontEx(hStdOut, 0, lpConsoleCurrentFontEx);

}

Then just call (for example):

setFontSize(20,20);
0
source

All Articles