Why does setlocale give me ? instead of normal letters? - c

Programming language: C
IDE: CodeBlocks
Compiler: GNU GCC Compiler
OS: Windows 7
My cmd defaults to code page 852, so I decided to use setlocale(), to set it to code page 437 using
setlocale(LC_ALL, "English_United States.437")
But doing so would make some letters/symbols display as '?' instead. Any way to fix this?

So I found 2 solutions.
1.
You can change the systems default code page under control panel, but it will require to restart the computer and is very impractical, but you can use raster fonts.
2.
Using "system("chcp 437");" will set the code page to 437, but you will need to use a font like "Lucida Console" to display characters/symbols as raster fonts for some reason can't print characters/symbols correctly if you change the code page like that.

Related

Print greek characters in CLion IDE

OS - Windows 8.1
IDE - CLion 2021.3.2
I need to print some greek characters but what I have is these symbols: ╬╗ , ╬╝ , ¤ü
What am I doing wrong? This is my settings for file encodings:
Set your console font to a Unicode TrueType font and emit the data using an "ANSI" mechanism.
For example this code prints γειά σου:
#include "windows.h"
int main()
{
SetConsoleOutputCP(1253); //"ANSI" Greek
printf("\xE3\xE5\xE9\xDC \xF3\xEF\xF5"); // encoded as windows-1253
return 0;
}
I resolved installing an old version of Clion (v 2021.1.3) default settings.
Others tentatives changing that not worked:
I had tried to reset the default settings in Clion v 2021.3.2
SetConsoleOutputCP(CP_UTF8); but I needed to change c standard from C99-->C90 in CMakeLists.txt to work
Regarding the negative score, maybe it was a banal question, but I tried to solve it from a week unsuccessfully. I am not an expert in the language C or in computer science in general, and I just did not have others to ask how to solve my problem, thus I have only wanted some help.
While you work on CLion open the file in notepad++ then menu Encoding - Encoding in ANSI, and save. In your open CLion you will see that the file was loaded in a wrong encoding:'UTF-8'. Click on reload in 'windows-1253' and you 'll be OK.CLion reload in windows 1253

Displaying Text with SDL_ttf without font file hard code

I have code in C LANGUAGE to display text on screen using SDL_ttf library in linux.
TTF_Font *font;
font = TTF_OpenFont("FreeSans.ttf", 20);
But in this I don't want to give file name as hard coded or file path. so when I execute this programme on other Linux machine it should run fine. I don't want to keep always this font file with my executable.
Is there any way to write portable code for TTF_OpenFont ?
or i can use something else that can solve my problem ?
To avoid hardcoding fonts you need to integrate SFL_TTF with fontconfig.
Or use fontconfig through a higher-level framework like pango http://sdlpango.sourceforge.net/

C - How to change font size in Ncurses?

Is there anyway? I cant seem to find any function that does this. I tried googling this but could not find anything.
I do not believe it is possible. The terminal is not for such things. It is meant for displaying text in sometimes varying colors. If you want to change the font size, you would need to open a window and draw to it (That might not actually be the correct term. Graphics aren't my forte). If this is what you want to do, I suggest looking into sdl. It is fairly simple to set up and is easy (IMO) to use. And because I know stackoverflow doesn't like flamewars, I am by no means saying it is the best. Im sure there are plenty of alternatives that are just as good. I just have not used them
If the text is being displayed in an xterm then it can be changed.
Edit .Xresources and add (probably at the top):
xterm*font: *-fixed-*-*-*-20-*
xterm*geometry: 80x24+5+5
This specifies a font size of 20 with a 80x24 charactor xterminal window located in the upper left of the display (widthxheight+xoffset+yoffset)
I was unable to use a font larger than 20. I start the application from a terminal window with the command line below on Ubuntu 14.04 with XFCE GUI.
xterm -e my_c_app
Well, it can be done if you are running on Windows command windows. I did that.
Ncurses will use your console windows settings: colors, size and typeface.
This works, but it is a somewhat basic mode of use. If needed you can even change the character attributes by program, before initializing ncurses terminal.
I tried with monospaced typefaces without any problems, tried even with proportional typefaces. It works also, but here visual quality is lesser due to the "entangling" of some characters, because ncurses keeps spacing in monospace mode.
I didn't try (yet) to change the character mode "in flight", but believe that this is possible. But i think that you can use only one mode/size for a time, that is: you cannot mix typefaces / sizes at the same screen.
There's no way with ncurses, but certain terminals support changing fonts. For xterm, for example:
$ echo -e '\x1b]50;-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso10646-1\a'
XTerm Control Sequences
Change Terminal Font Size with C++

print text in color in C under Cygwin

I have some code in C to print out lines of text in different colors.
It's working on Linux using escape characters (for example here).
It's working on Windows using SetConsoleTextAttribute
But my problem is when using Cygwin.
Escape characters don't work on Cygwin.
And calls to GetConsoleScreenBufferInfo always failed, and getLastErrorText() gives me this message:
Incorrect function. (0x1).
So my question is: how to print text in color from a C program running in a Cygwin terminal?
Do I need to install special libraries?
Thanks SzG and M Oehm for you comments.
As you said, M Oehm, the linux example is working.
I found the problem in my code. I was using the color value for Windows instead of the ones for Linux.
For example:
_ftprintf(target, TEXT("%c[%d;%dm%s%c[K\n"),
0x1B, foreground, background, printBuffer, 0x1B);
The values for foreground and background were not correct.
Now it's working.

Motif programming and UTF-8

I'm new to Motif programming and I want to use UTF-8 encoding.
I've tried XtSetLanguageProc (NULL, NULL, NULL); but when I read a file in Motif (editor text-like in 6A volume motif programming), I've got problems with accented characters.
I had to use setlocale()?
thanks!
With Motif, you have to switch to the correct font for the languages that you are using. There is currently no single UTF-8 font that has full support for all languages.
If there is more to your problem you might want to ask it on MotifZone http://www.motifzone.com/forum/unicode-support since Motif is not a commonly used toolkit anymore.
As Michael said, you need a font that supports Unicode. The ones with most broad support are Iso10646 fonts. Assuming Linux with X11, launch xfontsel to find them. Select iso10646 from the rgstry drop-down menu. Then fmly menu will list available fonts with that encoding. Some are very limited, but
-*-fixed-medium-*-*-*-18-*-*-*-*-*-iso10646-*
is a good choice that comes with the X11 installation.
Then, you need either to set that font as a fallback in your Motif program or supply the resource via command-line
xmprogram -xrm '*fontList: -*-fixed-medium-*-*-*-18-*-*-*-*-*-iso10646-*'
If all worked right, there will be no problems with accented characters anymore.
For a font supporting even more glyphs, consider GNU Unifont.

Resources