gpt4 book ai didi

C 字符串特殊字符(葡萄牙语)

转载 作者:行者123 更新时间:2023-11-30 14:49:15 35 4
gpt4 key购买 nike

如何在 C 中使用字符串正确处理特殊葡萄牙字符,例如:ç、é、è 等?

我找到了如何使用 printf 但 scanf、fgets 等来做到这一点...我现在不知道如何在字符串上正确存储这种字符...

#include <locale.h>

int main (void){
setlocale(LC_ALL,"Portuguese");

printf("This is a example! Portuguese caracters ç é");

}

编辑:

按照以下建议尝试此代码:

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <wchar.h>


int main() {
int a = 0;
setlocale(LC_ALL,"Portuguese");

wprintf(L"Exemplo de ç\n");

return 0;
}

从控制台手动编译它: gcc -o main.exe main.c 有效。但是使用 devc++ 给了我一个错误:

[错误]转换为执行字符集:参数无效

如果我只输入:wprintf(L"Exemplo de\n"); (没有 ç)devc++ 现在可以很好地编译。

因此,一旦手动编译它,我猜这与 devc++ 编译选项有关......有人知道吗?

编辑2:

我所有这一切的主要目标是询问用户输入。读取该输入以保存到文件中。每次程序启动时,我都会读取文件以恢复文件中保存的值。

但在葡萄牙语中,用户可以键入 ç、é、è ... 等内容

最佳答案

您可以像其他人一样使用 locale.h。但如果您想节省一些存储空间或使代码运行得更快,您可以使用该字符的 ASCII 含义。一个例子:

#include <stdio.h>
int main()
{
printf("Oo! Special character: %c",141);
return 0;
}

关于C 字符串特殊字符(葡萄牙语),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49731294/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com