Ryan W
Ryan W

Reputation: 31

Visual Studio C Program: How to print symbols for card suits?

I'm trying to make a card game and I want to use the actual card suit symbols to print cards as so:
5♣ J♦ 10♠ Q♥

Problem is I literally have zero idea how to code these symbols to print successfully in a program.

Upvotes: 1

Views: 6396

Answers (2)

Weather Vane
Weather Vane

Reputation: 34575

With Windows console font set to "Lucida Console" the following works:

#include <stdio.h>

int main (void)
{
    int i;
    for(i=3; i<=6; i++)
         printf("%c", i);
    printf("\n");
    return 0;
}

Program output:

♥♦♣♠

Similarly with "Consolas" font.

Upvotes: 1

Sean
Sean

Reputation: 62522

You'll need to use the unicode characters for those symbols along with a font that supports them. This page lists the unicode character code for various suits. They are:

Spade = U+2660, Heart = U+2665, Diamond = U+2666, Heart = U+2663

This will give you black suits. There's also characters for white suits.

You'll also need to make sure you are using wchar_t to represent the characters, not char as it won't be wide enough. Also, make sure you use functions like wprintf to do your output.

Upvotes: 1

Related Questions