#include <stdio.h>
int main()
{
int i;
int j;
for(i=32,j=2;i++;i<256)
{
if((i%16==0)
{
printf("\n%d:",j);
j++;
}
printf("%c ",i);
}
return 0;
}
编译后报错:
~/run$ gcc -Wall -o ascii ascii.c
ascii.c: In function ‘main’:
ascii.c:7:2: warning: statement with no effect [-Wunused-value]
for(i=32,j=2;i++;i<256)
原因是:for格式用错:修改为: for(i=32,j=2;i<256;i++)后就ok
修改后的代码:
#include <stdio.h>
int main()
{
int i;
int j;
for(i=32,j=2;i<256;i++)
{
if((i%16)==0)
{
printf("\n%2d:",j);
j++;
}
printf("%c ",i);
}
printf("\n");
return 0;
}
执行结果:
2: ! " # $ % & ' ( ) * + , - . /
3:0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4:@ A B C D E F G H I J K L M N O
5:P Q R S T U V W X Y Z [ \ ] ^ _
6:` a b c d e f g h i j k l m n o
7:p q r s t u v w x y z { | } ~
8:▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒
9:▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒
10:▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒
11:▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒
12:▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒
13:▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒
14:▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒
15:▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒