Ok, so after posting this question I tried to use the solutions provided in the related questions (particularly this) pointed by the community but I had another problem.
When trying to use the _setmode() function to change the Windows console to print UTF characters I get a debug error, just like the one posted on this other question. The debug error is as follows:
Text:
Debug Assertion Failed!
Program:
...kout-Desktop_Qt_5_5_0_MSVC2013_64bit-Debug\debug\Breakout.exe
File: f:\dd\vctools\crt\crtw32\stdio\output.c
Line: 1033
Expression: ((_Stream->_flag & _IOSTRG) || ( fn = _fileno(_Stream), (
(_textmode_safe(fn) == _IOINFO_TM_ANSI) &&
!_tm_unicode_safe(fn))))
For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
Screenshot:
Without the _setmode() function I still can't print characters from the upper ASCII Table, like these: "┌──┐". What can I do to solve this problem? The solution to the question with the same problem doesn't work also.
Again, I'm using Qt Creator on Windows, with Qt version 5.5.0 MSVC 64 bits. The compiler is the Microsoft Visual C++ Compiler 12.0 (amd64).
Edit:
Here's a small sample code that causes the error:
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
int main(void)
{
//Using setmode to force the error
_setmode(_fileno(stdout), _O_U16TEXT);
printf("Hello World!\n");
return 0;
}
Upon execution the error appears.
It seems that if you set the output mode to UTF-16, you must then use wprintf instead of printf.
(Presumably, since you have told the runtime to translate from UTF-16, you have to provide UTF-16.)
This code runs on my machine:
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
int main(void) {
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(L"\x043a\x043e\x0448\x043a\x0430 \x65e5\x672c\x56fd\n");
return 0;
}
So does
wprintf(L"Hello world!\n");
PS - I'm not sure whether this will solve your underlying problem, which I suspect has to do with the encoding of the source file. Even if using UTF-16 does solve your problem, it probably isn't the best solution.
Related
#include <locale.h>
#include <stdio.h>
#include <wchar.h>
int main() {
setlocale(LC_ALL, "");
wchar_t test = L'づ';
printf("%ls", L"\x3065");
printf("%lc", test);
return 0;
}
the expected output is: づづ, but
these two printf does not print anything, what can i do to solve this problem?
printf is a narrow string function and unless you have requested UTF-8 in your manifest and are running on an appropriate version Windows 10 it is not going to print Unicode correctly in all cases.
Use wprintf to print wide strings. Depending on the C runtime library, you might need to call _setmode(_fileno(stdout), _O_U16TEXT); first before printing.
Even if your program does everything correctly it might still not work in the console. Using the new Windows Terminal should work. The older console might just display squares. This is a console/font limitation. Copy the squares to the clipboard and paste in Wordpad to see that your program actually worked correctly.
See also:
Myth busting in the console
I'm trying to learn how to program in C.
I'm simultaneously learning C, C++, & Java. I have also coded in html and javascript successfully making rich websites.
I'm following video lessons on skillshare. Through VirtualBox I've set up a ubuntu installation, created lesson001.c, and attempted to compile it by entering "gcc lesson001.c"
The program:
#include <studio.h>
int main(){
printf("hello, world!\n");
return 0;
}
The error:
lesson001.c:1:10 fatal error: studio.h: no such file or directory.
The instructor is walking through the coding lesson on a pre-configured linux system, so he does have the same errors. It is frustrating that a comprehensive paid lesson set does not include critical setup parameters.
additional info: "gcc -v" returns about 20 lines of information on gcc 9.3.0, so I believe it is installed correctly.
Thank you
Change the #include <studio.h> declaration to #include <stdio.h>. A header file named studio.h does not exist in the standard library.
stdio stands for "standard input/output," and has nothing to do with "studio"! 😀
It should be stdio instead of studio.
stdio stands for Standard Input Output
Correctly formatted code :
#include <stdio.h>
int main(){
printf("hello, world!\n");
return 0;
}
I am compiling my application code on Solaris 5.11, Code is written in C.In the application code I used "fdio" related code. The Solaris box do not have that . How to get the sys/fdio package.
#include <stdio.h>
#include <sys/fdio.h>
int main()
{
printf("Hello World");
}
"test1.c", line 2: cannot find include file:
The file is no longer available in Solaris 11. Here is a copy that will help you compile your code. Drop it in /usr/include/sys It is opensource so there should be a few copies out there.
I am trying to use VSCode for writing and executing C codes for a course in Windows 10. I installed VSCode and MinGW as the instructions said. I'm trying to run a simple code (print "Hello world"), but when I run the code, the output says "Access denied"
//Test code for C in Windows 10
#include "stdio.h"
#include "stdlib.h"
void main(){
printf("Hello world");
}
I'm not sure if it's gonna solve your problem but when you include header from LibC or any different lib you must use this syntax
#include <stdio.h>
#include <stdlib.h>
If you use < symbol, the preprocessor will look in special path defined by your environement else if you use " symbol, the preprocessor will look in your current directory,
I have been using Ludvig Jerabek's port of the GNU getopt on Windows and getting errors on lines like:
if (d->optind != argc && !_tcscmp(argv[d->optind], _T("--")))
_tcscmp is a macro that resolves to strcmp on my system and then it reports strcmp not found. If we examine the headers in getopt.cpp:
/* Getopt for Microsoft C
....
Date: 02/03/2011 - Ludvik Jerabek - Initial Release
....
Revisions:
....
08/09/2011
....
#include <stdlib.h>
#include <stdio.h>
#include "getopt.h"
We see the problem: <string.h> is not included. I guess in Visual Studio <string.h> is included automatically maybe? I know I have successfully built getopt.cpp in Visual Studio, but using a manual environment with gcc on MinGW it is complaining about all the string compare functions being missing. What is the explanation for this?
The real tchar.h causes either #include <string.h> or #include <mbstring.h> depending on the character-set macros.
You have a broken version of tchar.h that does not correctly emulate these Microsoft-specific "Generic-Text Routine Mappings".