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
Related
I searched and tried some solutions, none worked.
ansi escape sequences - only works for unix-based
textcolor() (conio.h and curses.h) - only in turbo c++
graphic.h - doesn't really fix it, you'd have to change your .c files to .cpp every time
Is there a simple, or simple-ish, way to print color in c?
Newer Windows can use the Unix way by enabling Virtual Terminal Sequences in the console.
Older Windows need to use SetConsoleTextAttribute. See https://learn.microsoft.com/en-us/windows/console/console-screen-buffers#character-attributes.
For example, if you want to turn text red, you'd do
#include "Windows.h"
void MakeRed() {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED);
}
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.
I'm trying to start using code::blocks to do some C programming in just to learn. I was hoping to use the codecompletion / calltips feature (e.g. when typing say "printf" it popsup a handy dropdown box that shows the parameters.
I've made a new project and a new file in that project called "hello.c"
#include <stdio.h>
int main(){
int test=0;
printf("%d",test);
return 0;
}
but midway through typing prin---only "priority_queue and private" show up, no printf functions, and nothing happens when pressing ctrl-j, ctrl-space, alt-shift-space, ctrl-n or p nothing works. I've tried reparsing the project. I initially had 13.12 version installed because that's what Ubuntu (14.04.4LTS) had but then I installed version 16.01 by mucking with the apt-get ppas. That version also doesn't work. I've tried disabling and reenabling the code completion plugin and I've made sure under settings->editor-> that code completion box is checked.
What am I doing wrong here? Any help would be very appreciated. Thanks so much!
The new Code::Blocks IDE is not so polished on Ubuntu yet. You can try reinstalling it. And if it didn't work try reverting to 13.12.
I'm programming in windows, but in my C console some characters (like é, à, ã) are not recognizable. I would like to see how can I make widows interpret those chars as using unicode in the console or utf-8.
I would be glad for some enlightening.
Thank you very much
By console do you mean cmd.exe? It doesn't handle Unicode well, but you can get it to display "ANSI" characters by changing the display font to Lucida Console and changing the code page from "OEM" to "ANSI." By the choice of characters you seem to be Western European, so try giving this command before running your application:
chcp 1252
If you want to try your luck with UTF-8 output use chcp 65001 instead.
Although I completely agree with Joni's answer, I think it can be added a detail:
Since Telmo Vaz asked about how to solve this problem for C programs, we can consider the alternative of adding a system command inside the code:
#include <stdlib.h> // To use the function system();
#include <stdio.h>
int main(void) {
system("CHCP 1252");
printf("Now accents are right: áéíüñÇ \n");
return 0;
}
EDIT It is a good idea to do some experiments with codepages. Check the following table for information (under Windows):
Windows Codepages
I am having some problems writing to a file in unicode inside my c program. I am trying to write a unicode Japanese string to a file. When I go to check the file though it is empty. If I try a non-unicode string it works just fine. What am I doing wrong?
setlocale(LC_CTYPE, "");
FILE* f;
f = _wfopen(COMMON_FILE_PATH,L"w");
fwprintf(f,L"日本語");
fclose(f);
Oh about my system:
I am running Windows. And my IDE is Visual Studio 2008.
You might need to add the encoding to the mode. Possibly this:
f = _wfopen(COMMON_FILE_PATH,L"w, ccs=UTF-16LE");
Doing the same with fopen() works for me here. I'm using Mac OS X, so I don't have _wfopen(); assuming _wfopen() isn't returning bad stuff to you, your code should work.
Edit: I tested on cygwin, too - it also seems to work fine.
I cannot find a reference to _wfopen on either of my boxes, I however don't see why opening it with fopen should cause a problem, all you need is a file pointer.
What matters is if or not C recognizes the internal Unicode's values and pushes those binary values to the file properly.
Try just using fopen as Carl suggested, it should work properly.
Edit: if it still doesn't work you may try defining the characters as their integer values and pushing them with fwprintf(), I know that's cumbersome and not a good fix in the long run, but it should work as well.