在ANSI C中打印扩展ASCII [英] Print Extended ASCII in ANSI C

查看:90
本文介绍了在ANSI C中打印扩展ASCII的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在C中打印扩展的ASCII?

我尝试编写代码,但它只显示奇怪的符号。

这里是我的代码:


main()

{

char chr = 177; //存储符号的扩展ASCII

printf(带有ascii代码177的字符:%c \ n,chr);

//尝试打印ASCII符号...


返回0;

}


thankx

解决方案

ramif写道:


有没有办法在C ??中打印扩展的ASCII?



无法保证甚至打印ASCII字符,因为C是

字符编码不可知,除了某个基本的事实

必须有一组字符,并且

中字符的值0 ... 9必须是连续的。


我尝试编写代码,但它只显示奇怪的符号。

这里是我的代码:


main()

{

char chr = 177; //存储符号的扩展ASCII

printf(带有ascii代码177的字符:%c \ n,chr);

//尝试打印ASCII符号...


返回0;

}



如果你确保您的机器支持扩展字符

尝试:


#include< stdio.h>


int main(void){

unsigned char c;


for(c = 32; c< = 255; c ++)putc(c, stdout);

返回0;

}


santosh写道:
< blockquote class =post_quotes>
ramif写道:


>有没有办法在C ??中打印扩展的ASCII?



无法保证甚至打印ASCII字符,因为C是

字符编码不可知,除了某个基本的事实

必须有一组字符,并且

中字符的值0 ... 9必须是连续的。


>我尝试编写代码,但它只显示奇怪的符号。
这是我的代码:

main()
{
char chr = 177; //存储符号的扩展ASCII
printf(带有ascii代码177的字符:%c \ n,chr);
//尝试打印ASCII符号...

返回0;
}



如果您确定您的机器支持扩展字符

试试:


#include< stdio.h>


int main(无效){

unsigned char c;


for(c = 32; c< = 255; c ++)putc(c,stdout);

返回0;

}



我尝试了你的代码,gcc给了我以下警告:

"警告:比较是因为数据类型的范围有限而总是如此


BTW,我正在使用在x86_64架构上运行的Linux Fedora 7。 GCC

版本是4.1.2 20070925


你认为我的电脑支持扩展的ASCII吗?


几个月前,我已经写了一个Pascal程序(在Windows XP上)

显示扩展的ASCII并且它没有任何问题。


ramif写道:


santosh写道:


> ramif写道:


>>有没有办法在C ??中打印扩展的ASCII?


无法保证甚至打印ASCII字符,因为C是字符编码不可知的,除了某个基本
字符组必须是可用且0到9范围内的字符值
必须是连续的。


>>我试图编写代码,但是它只显示奇怪的符号。
这是我的代码:

main()
{
char chr = 177; //存储符号的扩展ASCII
printf(带有ascii代码177的字符:%c \ n,chr);
//尝试打印ASCII符号...

返回0;
}


如果您确定您的机器支持扩展字符,请尝试:

#include< stdio.h>

int main(void){
unsigned char c;

for(c = 32; c< ; = 255; c ++)putc(c,stdout);
返回0;
}



我试过你的代码,gcc给了我以下警告:

警告:由于数据范围有限,比较始终为真

type



哎呀,再次被无符号的bug咬了!


将''c'的类型改为int。


BTW,我正在使用在x86_64架构上运行的Linux Fedora 7。 GCC

版本是4.1.2 20070925


你认为我的电脑支持扩展的ASCII吗?


几个月前,我已经写了一个Pascal程序(在Windows XP上)

显示扩展的ASCII并且它没有任何问题。



正如理查德所说,大多数系统都支持扩展字符,但

究竟哪个集当前适用的是系统相关的。 C

语言只保证它的基本源和

执行字符集中的字符存在。除此之外,所有内容都依赖于实施。


Is there a way to print extended ASCII in C??

I tried to code something, but it only displays strange symbols.
here is my code:

main()
{
char chr = 177; //stores the extended ASCII of a symbol
printf("Character with an ascii code of 177: %c \n", chr);
//tries to print an ASCII symbol...

return 0;
}

thankx

解决方案

ramif wrote:

Is there a way to print extended ASCII in C??

There is no guarantee to even print the ASCII characters as C is
character encoding agnostic, except for the fact that a certain basic
set of characters must be available and that the value of characters in
the range 0... 9 must be continuous.

I tried to code something, but it only displays strange symbols.
here is my code:

main()
{
char chr = 177; //stores the extended ASCII of a symbol
printf("Character with an ascii code of 177: %c \n", chr);
//tries to print an ASCII symbol...

return 0;
}

If you are sure that your machine as support for extended characters
try:

#include <stdio.h>

int main(void) {
unsigned char c;

for (c = 32; c <= 255; c++) putc(c, stdout);
return 0;
}


santosh wrote:

ramif wrote:

>Is there a way to print extended ASCII in C??


There is no guarantee to even print the ASCII characters as C is
character encoding agnostic, except for the fact that a certain basic
set of characters must be available and that the value of characters in
the range 0... 9 must be continuous.

>I tried to code something, but it only displays strange symbols.
here is my code:

main()
{
char chr = 177; //stores the extended ASCII of a symbol
printf("Character with an ascii code of 177: %c \n", chr);
//tries to print an ASCII symbol...

return 0;
}


If you are sure that your machine as support for extended characters
try:

#include <stdio.h>

int main(void) {
unsigned char c;

for (c = 32; c <= 255; c++) putc(c, stdout);
return 0;
}

I tried your code, and gcc gave me the following warning:
"warning: comparison is always true due to limited range of data type"

BTW, i''m using Linux Fedora 7 running on x86_64 architecture. GCC
version is 4.1.2 20070925

Do you think that my PC supports extended ASCII??

A few month ago, i''ve written a Pascal program (on Windows XP) that
displays the extended ASCII and it worked without any problems.


ramif wrote:

santosh wrote:

>ramif wrote:

>>Is there a way to print extended ASCII in C??


There is no guarantee to even print the ASCII characters as C is
character encoding agnostic, except for the fact that a certain basic
set of characters must be available and that the value of characters
in the range 0... 9 must be continuous.

>>I tried to code something, but it only displays strange symbols.
here is my code:

main()
{
char chr = 177; //stores the extended ASCII of a symbol
printf("Character with an ascii code of 177: %c \n", chr);
//tries to print an ASCII symbol...

return 0;
}


If you are sure that your machine as support for extended characters
try:

#include <stdio.h>

int main(void) {
unsigned char c;

for (c = 32; c <= 255; c++) putc(c, stdout);
return 0;
}


I tried your code, and gcc gave me the following warning:
"warning: comparison is always true due to limited range of data
type"

Oops, bitten by the unsigned bug again!

Well change the type of ''c'' to int.

BTW, i''m using Linux Fedora 7 running on x86_64 architecture. GCC
version is 4.1.2 20070925

Do you think that my PC supports extended ASCII??

A few month ago, i''ve written a Pascal program (on Windows XP) that
displays the extended ASCII and it worked without any problems.

As Richard said, most systems do support extended characters, but
exactly which set is currently applicable is system dependant. The C
language only guarantees that the characters in it''s basic source and
execution character set are present. Beyond that everything is
implementation dependant.


这篇关于在ANSI C中打印扩展ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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