输出中文c语言,输出英文c语言

发布时间:2022-12-01

本文目录一览:

1、c语言中如何打出中文?
2、请问在C语言中如何输出汉字?
3、c语言怎样才能输出中文???(最简单的方法)

c语言中如何打出中文?

1、中文字符串可以使用printf()puts()等函数直接输出。

#include stdio.h
#include locale.h
int main()
{
    const char str[] = "这里全是中文";
    printf("\n输出字符数:%d\n", printf(str));
    puts(str);
    return 0;
}

2、单个中文字符,需要进行本地化设置,需要使用宽字符版的printf()wprintf输出。

#include stdio.h
#include locale.h
int main()
{
    setlocale(LC_ALL, "chs");
    wchar_t wc = L'中';
    wprintf(L"%c\n",wc);
    return 0;
}

请问在C语言中如何输出汉字?

1、引入标准输入输出库:sdtio.h
2、定义字符串形式的汉字(采用字符数组存储)。
3、使用printf函数,或者puts函数输出字符串形式的汉字。 例如:

#include stdio.h
int main()
{
    char str[]="输出汉字";
    printf("%s\n",str);
    puts(str);
    return 0;
}
运行结果:
输出汉字
输出汉字

c语言怎样才能输出中文???(最简单的方法)

定义一个字符串变量,在这个变量的值中就可以输入中文了。汉字是多字节的,一个char放不下,可以使用字符数组,但需要给数组分配空间,或者使用string。 例如:

#include stdio.h
int main(void)
{
    char a[128];
    printf("请输入所需输出的汉字:");
    scanf("%s",a);
    printf("%s\n",a);
    return 0;
}