visual studio - C programming (beginner help) Ascii table -


hi need c programming . need write ascii table without numbers : 0, 7-10 , 13 . between every char "\t" , after every 10 chars skip line . code :

void ascii() {     int i;     (i = 0; <= 255; i++)     {         if (i == 0)         {             printf("\t");          }         if (0 == % 10)         {             printf("\n");         }                printf("%d = %c\t", i, i);      }     return; } 

why codes excluded? wouldn't better exclude non-printable codes? isprint that.

    #include <ctype.h>      if (isprint(i)) printf("%d = %c\t", i, i); 

if want exclude particular codes, can use same technique isxxx functions:

char is_print[256] = { 0,1,1,1,1,1,1,0,0,0,0,1,1,0,1,1, /* 0 in pos 0, 7-10 , 13 */                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }; /* filter 0 chars want exclude. */   int myisprint(char c) {     return is_print((unsigned char)c); /* use filter */ } 

and in function:

if (myisprint(i)) printf("%d = %c\t", i, i); 

note:

in simple cases might use if tests particular codes if (i != 0 && != 13 && (i < 7 || > 10)) print.... filter technique described above has advantage of being lightning fast, , code easy read, if number of cases large.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -