c语言acsii输出梅花

c语言用printf("%c", 6)无法输出红桃,只输出小方框,代码及结果如图

img

img

打印前调用setfont函数设为点阵字体。


#include<Windows.h>
void setfont()
{
    CONSOLE_FONT_INFOEX cfi = { 0 };
    cfi.cbSize = sizeof(cfi);
    cfi.dwFontSize.X = 10;
    cfi.dwFontSize.Y = 18;
    cfi.FontWeight = FW_NORMAL;
    wcscpy(cfi.FaceName, L"Terminal");
    SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), NULL, &cfi);
}

啥意思?你用啥环境?

img


参考一下
https://blog.csdn.net/Env1sage/article/details/128040886

在代码里加SetConsoleOutputCP(437);和Windows.h头文件

#include <stdio.h>
#include <Windows.h>
int main()
{
    SetConsoleOutputCP(437);
    printf("%c",6);
    return 0;
}

你有尝试这个操作不?
首先用你的这种写法的化,方片要加上括号。
其次,如果在控制台打印不出来图案(出来的是小方框)
可以右键点击运行出现的控制台左上角
选择“默认值”
选择“字体”页面
选择“字体”下拉框的“点阵字体”
点击“确定”
重新运行一下即可
参考链接:https://blog.csdn.net/Env1sage/article/details/128040886

6是黑桃,要#include <stdio.h>和#include <Windows.h>,还要 SetConsoleOutputCP(437);
参考程序

#include <stdio.h>
#include <Windows.h>
int main()
{
    SetConsoleOutputCP(437);
    printf("%c\n",3);
    printf("%c\n",4);
    printf("%c\n",5);
    printf("%c\n",6);
    return 0;
}
 

环境配置问题,参考下

方法1:编程设置
在stdio头文件的基础上加上#include <Windows.h>头文件
之后在主函数中进行设置SetConsoleOutputCP(437);
设置完成后再输出就正常了。


方法2:直接设置
1️⃣右键点击运行出现的控制台左上角
2️⃣选择“默认值”
3️⃣选择“字体”页面
4️⃣选择“字体”下拉框的“点阵字体”
5️⃣点击“确定”
6️⃣重新运行一下即可。


如有帮助,还请采纳!谢谢!

rintf 函数的第一个参数是一个格式字符串,其中的 %c 表示后续参数为一个字符。在上述代码中,传递给 printf 函数的第二个参数为整数 6,而非一个字符。因此,输出的是无效的字符,导致了乱码的输出。

要想输出红桃,可以将 printf 函数的第二个参数改为红桃字符 '\u2665'。例如:


#include <stdio.h>

int main() {
    printf("%c\n", '\u2665'); // 输出红桃
    return 0;
}