2010-08-07 60 views
0

我有计划,打印所有字符从CHAR_MIN这里CHAR_MAX是代码字符打印程序

#include <limits.h> 
#include <stdio.h> 
#include <stdlib.h> 
int main(){ 
    char c; 
    c=CHAR_MIN; 
    while(c!=CHAR_MAX){ 
      printf("d\n",c); 
      c=c+1; 

    } 


return 0; 



} 

但它只是所有D型打印为什么?输出中是这样

d 
d 
d 
d 
d 
d 
d 
d 
d 
d 

...

。 。按任意键继续

+0

这真是一个好问题.....我没有看到它的权利。 – tristan 2010-08-07 12:38:45

回答

6
printf("d\n",c);  /// Means just print "d" (c is ignored) 
printf("%d\n",c);  /// Means print the decimal value of varaible c 
printf("%c\n",c);  /// Means print the charcter value of varaible c 

使用 “%d”,将只打印 “0”, “1”, “2” 等

使用 “%C” 将打印的字符的值:“A “,”B“,”C“等。但请注意,前31个不可打印。

2

更换

printf("d\n",c); 

printf("%c\n",c); 
+0

看看http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output – 2010-08-07 13:01:05