-3

I wrote the following code to generate Unicode symbols for card suits in C. I don't need to change the font family or the code page of the console (I use Windows 10 and Dev-C++) but it seems that I can generate only those symbols.

For instance, if I try other known good Unicode values which correspond to existing glyphs (i.e. chess board pieces, dice faces, dominos or others more 'rare' or less commonly used symbols) as shown here in the black photo below my code, the symbols will not render for me locally on my screen.

Why can I not see the symbols?

Here is my C code which prints out all 4 cards regardless of switch/case decision:

#include <stdio.h>
#include <fcntl.h>
    
#define SPADE L"\u2660"
#define CLUB L"\u2663"
#define HEART L"\u2665"
#define DIAMOND L"\u2666"
    
enum SUIT {spade = 1, club, heart, diamond};
    
    
void printSuit(int suitToSelect){
  _setmode((_fileno(stdout), _O_U16TEXT);

  switch (suitToSelect){

    case spade:
    wprintf(SPADE);
    break;

    case club:
    wprintf(CLUB);
    break;

    case heart:
    wprintf(HEART);
    break;

    case diamond:
    wprintf(DIAMOND);
    break;
  }
  _setmode(_fileno(stdout), _O_TEXT);
}

int main(void){
  printSuit(spade);
  printSuit(heart);
  printSuit(club);
  printSuit(diamond);
  printf("\n");
  printf("Normal text\n");
  return 0; 
}

enter image description here

philipxy
  • 14,867
  • 6
  • 39
  • 83
horus
  • 91
  • 1
  • 9
  • 3
    What do you mean by "that code does not work"? Does it not compile, or throw an error when it runs, or do you mean that it compiles and runs fine but does not show the character(s) that you are trying to print? – lxop May 25 '20 at 20:45
  • It compiles but generates "?" instead of the symbol. Thank you. – horus May 25 '20 at 21:03
  • 3
    In that case I expect it is simply that the font family in your console doesn't have glyphs for the characters you are trying to print – lxop May 25 '20 at 21:05
  • 2
    Show the code which *does not* work instead (or in addition to) of the one that works. Note that there is a difference between symbols represented with 4 hex digits and the ones represented by more:https://en.wikipedia.org/wiki/Escape_sequences_in_C#Table_of_escape_sequences – Eugene Sh. May 25 '20 at 21:08
  • Sorry, perhaps I haven't been clear: the code compiles and works, but Unicode symbols don't appear even if I write their correspondent values. The visualization is correct only for card suits symbols. For example, all the chess symbols don't appear: they correspond to the values L"\u2654", L"\u2655", L"\u2656", L"\u2657"... see this wiki for a complete list: [en.wikipedia.org/wiki/Chess_symbols_in_Unicode] (en.wikipedia.org/wiki/Chess_symbols_in_Unicode) – horus May 26 '20 at 14:38
  • [Why should I not upload images of code/data/errors when asking a question?](https://meta.stackoverflow.com/q/285551/3404097) Please clarify via edits, not comments. Please delete & flag obsolete comments. [Help] – philipxy Apr 29 '23 at 06:40

1 Answers1

0

The code below works with Dev-C++ and Windows 10.

See the screenshot of the console.

You can select different fonts in the code to visualize unicode symbols; each font family prints the symbols in different styles.

enter image description here

#include <windows.h>
#include <stdio.h>

int main(void)
{ 
    CONSOLE_FONT_INFOEX cfi;
    cfi.cbSize = sizeof cfi;
    cfi.nFont = 0;
    cfi.dwFontSize.X = 20;
    cfi.dwFontSize.Y = 40;
    cfi.FontFamily = FF_DONTCARE;
    cfi.FontWeight = FW_NORMAL;

    wcscpy(cfi.FaceName, L"Dejavu Sans Mono");
    //wcscpy(cfi.FaceName, L"MS Gothic");
    //wcscpy(cfi.FaceName, L"MS Mincho");
    //wcscpy(cfi.FaceName, L"NSimSun");
    SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
    
     SetConsoleOutputCP(65001);
     
    printf("\u2660 \u2661 \u2662 \u2663 \u2664 \u2665 \u2666 \u2667 \n");
    printf("\u265B \u265C \u265D \u265E\n");
    printf("\u265F \u265A \u2655 \u2656 \u2657\n");
    printf("\u2658 \u2659 \u2654 \n");
    printf("\u2680 \u2681 \u2682 \u2683 \u2684 \u2685\n");
    printf("\u2554 \u2555 \u2556 \u2563 \u255A \u255B \u255C \u255D\n");
    return 0;
}
philipxy
  • 14,867
  • 6
  • 39
  • 83
horus
  • 91
  • 1
  • 9
  • 1
    How does this answer the question? PS Please use standard spelling & punctuation. Please avoid social & meta content in posts. Please use text, not images/links, for what can be given as text. – philipxy Apr 29 '23 at 06:52