整数到char表问题 [英] integer to char table problems
问题描述
我正在尝试打印一个表,其中整数对应于什么
字符。有人可以告诉我这段代码有什么问题吗?
#include< stdio.h>
int main()
{
char line [9]; / * wordlist中的每个单词* /
char d;
for(d = 0; d< = 255; d ++)
printf(" int =%d \ tchar =%c \ nn,d,d);
}
提前致谢!
I am trying to print a table of what integer corresponds to what
character. Can someone please tell me what is wrong with this code?
#include <stdio.h>
int main()
{
char line[9]; /* each word in the wordlist */
char d;
for (d=0; d<=255; d++)
printf("int=%d\tchar=%c\n",d,d);
}
Thanks in advance!
推荐答案
AA写道:
我正在尝试打印一个整数对应什么的表
性格。有人可以告诉我这段代码有什么问题吗?
< stdio.h>
int main()
{
char line [9]; / * wordlist中的每个单词* /
char d;
for(d = 0; d< = 255; d ++)
printf(" int =%d \\ \\ ttt =%c \ n",d,d);
}
I am trying to print a table of what integer corresponds to what
character. Can someone please tell me what is wrong with this code?
#include <stdio.h>
int main()
{
char line[9]; /* each word in the wordlist */
char d;
for (d=0; d<=255; d++)
printf("int=%d\tchar=%c\n",d,d);
}
你不知道char类型是否可以达到255。
#include< stdio.h>
#include< limits.h>
int main(void)< br $> b $ b $
for(d = 0; d< = CHAR_MAX; d ++){
printf(" int =%d char =%c \ n",d,d);
}
返回0;
}
-
pete
You don''t know if type char can ever reach 255.
#include <stdio.h>
#include <limits.h>
int main(void)
{
int d;
for (d=0; d <= CHAR_MAX; d++) {
printf("int=%d char=%c\n", d, d);
}
return 0;
}
--
pete
pete写道:
printf(" int =%d char =%c \ n",d,d);
printf("int=%d char=%c\n", d, d);
它也可能有点微妙printf'的可变参数是
受默认促销限制 - 也就是说,printf并不关心你是否通过char,short或int传递
要么是%d,要么是%c参数;只有
会影响价值的显示方式(虽然循环当然很关心,但是如同皮特所指出的那样,b $ b。)
As令人困惑的是,在将NULL定义为0的平台上,您还可以将
传递给%d或%c参数的NULL,并且它将导致没有未定义的
行为,被视为int零。
-
Derrick Coetzee
我将此新闻组发布到公共领域。我不承担所有
明示或暗示保证并承担所有责任。我不是专业人士。
It may also be a little bit subtle that printf''s variadic arguments are
subject to the default promotions - that is, printf doesn''t care whether
you pass a char, short, or int for either a %d or %c argument; it only
affects how the value is displayed (although the loop certainly cares,
as pete points out.)
As a confusing aside, on platforms that define NULL as 0 you could also
pass NULL for a %d or %c argument, and it would cause no undefined
behaviour, being treated as the int zero.
--
Derrick Coetzee
I grant this newsgroup posting into the public domain. I disclaim all
express or implied warranty and all liability. I am not a professional.
" AA" < AA@example.com>在消息新闻中写道:Ill5d.8340
"AA" <AA@example.com> wrote in message news:Ill5d.8340
这篇关于整数到char表问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!