I've the following code:
#include <stdio.h>
#include <windows.h>
#include <process.h>
int main() {
/* DWORD WINAPI */void input(/* LPVOID */void* lpParam) {
Sleep(1000);
printf("hello mingw!\n");
// return 0;
}
_beginthread(input, 0, NULL);
getchar();
return 0;
}
I cross-compile from ubuntu 22.04.01 with mingw-w64 with:
...$ x86_64-w64-mingw32-gcc -o example.exe example.c
In a native Win7 box it works as expected:
...$ example.exe
hello mingw! (after 1 second)
a
...$
but in wine when entering 'a' from keyboard, the 'a' climbs up one line:
...$ example.exe
aello mingw!
...$
It seems as if printf output from a thread didn't update console cursor. This only happens when read code (getchar()) executes before the write code (printf), hence the Sleep.
Any pointers?
I have got problem with printing extended ascii in terminal using wprintw function. This program prints letters instead squares. I was trying to change my locales but without effect. What should I change in my system to print it correctly?
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include <unistd.h>
#include <locale.h>
#include <wchar.h>
int main(void)
{
setlocale(LC_ALL, "");
initscr();
WINDOW *game_window;
game_window=newwin(40,40,1,1);
wrefresh(game_window);
while (TRUE) {
wclear(game_window);
wprintw(game_window, "██████████████████████");
wrefresh(game_window);
sleep(3);
break;
}
endwin();
return 0;
}
I am working On Debian Jessie 10 and these are my locale:
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
Ok, I find the solution, when compiling the program you should use
this command:
gcc main.c -o main -lncursesw
Instead this:
gcc main.c -o main -lncurses
In a C program in Windows 10, I should print the word TYCHÊ on the screen, but I cannot print the letter Ê (Hex code: \xCA):
#include <stdlib.h>
#include <stdio.h>
char *Word;
int main(int argc, char* argv[]){
Word = "TYCH\xCA";
printf("%s", Word);
}
What's wrong?
Windows is a pain when it comes to printing Unicode text, but the following should work with all modern compilers (MSVC 19 or later, g++ 9 or greater) on all modern Windows systems (Windows 10 or greater), in both Windows Console and Windows Terminal:
#include <iostream>
#include <windows.h>
int main()
{
SetConsoleOutputCP( CP_UTF8 );
std::cout << "TYCHÊ" << "\n";
}
Make sure your compiler takes UTF-8 as the input character set. For MSVC 19 you need a flag. I think it is the default for later versions, but I am unsure on that point:
cl /EHsc /W4 /Ox /std:c++17 /utf-8 example.cpp
g++ -Wall -Wextra -pedantic-errors -O3 -std=c++17 example.cpp
EDIT: Dangit, I misread the language tag again. :-(
Here’s some C:
#include <stdio.h>
#include <windows.h>
int main()
{
SetConsoleOutputCP( CP_UTF8 );
printf( "%s\n", "TYCHÊ" );
return 0;
}
You can try with this line
printf("%s%c", Word, 0x2580 + 82);
this can print your Ê.
I used CLion for resolve it, on another IDE it may not give the same result.
In the Windows Command Line you should choose the Code Page 65001:
CHCP 65001
If you want to silently do that directly from the source code:
system("CHCP 65001 > NUL");
In the C source code you should use the <locale.h> standard header.
#include <locale.h>
At the beginning of your program execution you can write:
setlocale(LC_ALL, "");
The empty string "" initializes to the default encoding of the underlying system (that you previously choose to be Unicode).
However, this answer of mine is just a patch, not a solution.
It will help you to print the french characters, at most.
Handling encoding in Windows command line is not straight.
See, for example: Command Line and UTF-8 issues
I'm trying to discover libVLC sdk in windows 7. Every time I compile the code, I'm getting this error
main.c:(.text+0xf): undefined reference to `libvlc_clock'
I've included the path. This is my code
#include <stdio.h>
#include <inttypes.h>
#include <vlc\vlc.h>
#include <vlc\libvlc.h>
int main()
{
int64_t time = libvlc_clock();
return 0;
}
and this is the line in prompt command in windows 7
gcc main.c -o test -I"C:\Program Files (x86)\VideoLAN\VLC\sdk\include"
I have a problem with netbeans 7 about debugging and running C program, the problem is that after I wrote the code as the following
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("done");
"khaled";
return 0;
}
in the output panel everything goes well but there's not any real output project (excutable file) no window appears.
I use gcc complier as the C compiler.