C - Write program to output the printable characters for character code values from 0 to 127

Requirements

Write program to output the printable characters for character code values from 0 to 127

Output each character code along with its symbol with two characters to a line.

Make sure the columns are aligned.

Hint

You can use the isgraph() function from ctype.h to determine when a character is printable.

Demo

#include <stdio.h>
#include <ctype.h>

int main(void)
{
  char ch = 0;                       // Character code value
  for(int i = 0 ; i < 128 ; ++i)
  {// w  w  w.  j  av a 2  s .c o  m
    ch = (char)i;
    if(i%2 == 0)
      printf("\n");
    printf("  %4d    %c",ch,(isgraph(ch) ? ch : ' '));
  }
  printf("\n");
  return 0;
}

Result

Related Exercise