如何将非ascii字符放入C字符串? [英] How to put non-ascii characters into C string?

查看:119
本文介绍了如何将非ascii字符放入C字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我希望显示一些特殊字符,例如alpha字符的字符。和

符号表示..有人请给我一些建议怎么做?


非常感谢你!

欧文

Hi there,

I wish to show some special characters such as the char for "alpha" and the
symbol for degrees.. Anyone please give me some suggestions how to do that?

Thank you very much!

Owen

推荐答案

wob写道:
你好,

我希望显示一些特殊字符,例如alpha的字符。和度数的符号..任何人请给我一些建议怎么做?
Hi there,

I wish to show some special characters such as the char for "alpha" and the
symbol for degrees.. Anyone please give me some suggestions how to do that?




C标准保证存在基本执行

字符集"由大写和小写的非重音

字母组成,数字从零到九,各种标点符号,

和一些特殊用途的字符,如''\ n ''。无论你使用什么C

实现,这些字符都会出现,并且

可供您使用。


标准还允许(非

基本)执行字符集中的附加字符。但是,它不需要

存在其他字符,也不指定任何此类

附加字符。结果是任何这样的额外

字符只能在实现的时候出现,

和不同的实现将有不同的(可能是空的)

套额外字符。


产生alpha字符的数字字符代码一个实施可能会产生左上角。另一个和

欧元符号在另一个。因此,你要求

的方式是alpha。生产将特定于您的系统和

可能不适用于其他人;你可以发送alpha代码到

输出流,只看到笑脸或空白。


字符集和字符代码的标准化是

a相对较近的发展,C还没有追上它的b $ b。 C仍然对这些问题保持一种不可知性

(这就是为什么C很容易在使用不同的

角色曲目的系统上实现的),但它确实使一个人复杂化了希望

使用异国情调字符。甚至在拉丁字母的字母系列中也出现了麻烦:一个人不能写Cosífantutte

或G?tterd?mmerung或A?da或A?da。保证设施

by C.


所以:你们一直在努力想要找出这个不愉快的任务

什么字符代码(如果有的话)产生alpha字符。和系统上的度数符号

,并且认识到相同的代码可能不会对您使用的下一个系统做任何明智的事情。作为一个纯粹的实用和临时方法,你可以给自己写一个小的

程序,它贯穿每个`char''值并显示字形
你的系统为每个产生
。如果您碰巧发现alpha和

" degree symbol"在渲染的标志符号中你很幸运 - 但​​是

永远不要忘记相同的代码可以在其他系统上完全不同。

与其他系统不同。


这里有一个完美的世界,但我认为

我把它放在我其他裤子的口袋里。


- -

Eric Sosman
es ***** @ acm-dot-org .inva


wob写道:
我希望显示一些特殊字符,例如alpha字符的char。和度数的符号..任何人请给我一些建议怎么做?
I wish to show some special characters such as the char for "alpha" and the
symbol for degrees.. Anyone please give me some suggestions how to do that?




在我的Fedora Core 4系统上(使用Unicode UTF- 8)我实际上可以这样做:


#include< stdio.h>

#include< string.h>


int main(无效)

{

printf(" the character?±占据%i bytes.\ n,strlen(") ?±));

返回0;

}


并且程序将输出:


字符?±占用2个字节。


在Emacs中,可以插入特殊的Unicode字符和

`set-input-方法''和参数`TeX''。然后键入

` \ alpha''插入?±。 (如果没有UTF-8支持,此消息将无法正确显示。)

August



On my Fedora Core 4 system (which uses Unicode UTF-8) I can in fact do:

#include <stdio.h>
#include <string.h>

int main(void)
{
printf("The character ?± occupies %i bytes.\n", strlen("?±"));
return 0;
}

and the program will output:

The character ?± occupies 2 bytes.

In Emacs, special Unicode characters can be inserted with
`set-input-method'' and argument `TeX''. ?± is then inserted by typing
`\alpha''. (This message will not display correctly without UTF-8 support.)
August


" wob" < WO *** @ hotmail.com>写道:

#那里,



#我希望显示一些特殊字符,例如alpha字符的char并且

#符号为度。任何人都可以给我一些建议怎么做?


如果字形的编码不包括一个空字节,你可以使用fprintf

或fputs或%s或%c。然而,目前确定字形的编码

是不变的。这取决于字体或你是否使用Unicode,它给所有字体一个代码

。如果它是Unicode,你必须知道编码是什么

如UTF-8或Latin-1或MacRoman或......


它所有这些都取决于你想要指定一个字符的上下文,比如

" alpha"。

-

SM Ryan http://www.rawbw.com/~wyrmwif/

所以基本上,你只是追踪。
"wob" <wo***@hotmail.com> wrote:
# Hi there,
#
# I wish to show some special characters such as the char for "alpha" and the
# symbol for degrees.. Anyone please give me some suggestions how to do that?

If the encoding of the glyph doesn''t include a null byte, you can use fprintf
or fputs or %s or %c. However determining the encoding of glyphs at the moment
is in flux. It depends on the font or whether you''re using Unicode which gives
one code for all fonts. If it''s Unicode, you have to know what the encoding is
like UTF-8 or Latin-1 or MacRoman or ...

It all depends on the context in which you want to specify a character like
"alpha".
--
SM Ryan http://www.rawbw.com/~wyrmwif/
So basically, you just trace.


这篇关于如何将非ascii字符放入C字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆