CSM217: C for Computer Scientists

Lecture 4: Exercise 3: Solution


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

main() {
 int a = 0;
 
 for(a=0; a < 128; a++) {
  printf("ASCII %d is ", a); 
  switch(isprint(a)) {
   case 0: // isprint will return 0 if the test is false
    printf("%s\n", "unprintable");
    break;
   default:
    printf("%s %c\n", "character", a);
  }
 }
}