字符 - ASCII关系 [英] Char - ASCII relation

查看:177
本文介绍了字符 - ASCII关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C编程语言中的char是专为大到足以从编码的字符值存储,如ASCII一个固定大小的字节实体。

但到什么程度是与ASCII编码的字符的字符互换的整数值?有什么办法来指代A为65(十进制)?

的getchar()返回一个整数 - presumably这直接关系到这些价值?另外,如果我没有记错,这是在某些情况下可能增加字符...这样(粗略地说)'?'+ 1 =='@'。

,或者是此类编码不能保证是ASCII?它完全取决于特定的环境?是字符的处理等使用C不实际或不可能?

编辑:相关: C比较试样char和INT


解决方案

  

但到什么程度是与ASCII编码的字符的字符互换的整数值?有什么办法来指代A为65(十进制)?


事实上,你不能做任何事情。 字符仅仅是一个不可分割的类型,如果你写

 字符CH ='A';

然后(假设ASCII), CH 只会保存整数值 65 - $ P $它psenting到用户是不同的问题。


  

,或者是此类编码不能保证是ASCII码?


没有,它不是。 C不依赖于任何特定的字符编码​​。


  

是否完全取决于特定的环境?


是,pretty了。


  

字符是用C?

实际或不可能这样操作

没有,你就必须要小心,知道标准相当不错 - 那么你会是安全的。

A char in the C programming language is a fixed-size byte entity designed specifically to be large enough to store a character value from an encoding such as ASCII.

But to what extent are the integer values relating to ASCII encoding interchangeable with the char characters? Is there any way to refer to 'A' as 65 (decimal)?

getchar() returns an integer - presumably this relates directly to such values? Also, if I am not mistaken, it is possible in certain contexts to increment chars ... such that (roughly speaking) '?'+1 == '@'.

Or is such encoding not guaranteed to be ASCII? Does it depend entirely upon the particular environment? Is such manipulation of chars impractical or impossible in C?

Edit: Relevant: C comparison char and int

解决方案

But to what extent are the integer values relating to ASCII encoding interchangeable with the char characters? Is there any way to refer to 'A' as 65 (decimal)?

In fact, you can't do anything else. char is just an integral type, and if you write

char ch = 'A';

then (assuming ASCII), ch will merely hold the integer value 65 - presenting it to the user is a different problem.

Or is such encoding not guaranteed to be ASCII?

No, it isn't. C doesn't rely on any specific character encoding.

Does it depend entirely upon the particular environment?

Yes, pretty much.

Is such manipulation of chars impractical or impossible in C?

No, you just have to be careful and know the standard quite well - then you'll be safe.

这篇关于字符 - ASCII关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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