Skip to content

Instantly share code, notes, and snippets.

@mr-fool
Created June 19, 2014 16:50
Show Gist options
  • Select an option

  • Save mr-fool/7cf38f2c8d111a4de6a7 to your computer and use it in GitHub Desktop.

Select an option

Save mr-fool/7cf38f2c8d111a4de6a7 to your computer and use it in GitHub Desktop.
A C program that print ascii table using print buff
#include <stdio.h>
#define LOWER_BOUND 33 //since 1-33 is considered nonprintable prof said consider space and tab as nonprintable
#define UPPER_BOUND 127
int main() {
char row[9]; //8 characters a row
int c, d; //d is used to control the bounds of the row buffer
for (d = 0, c = 0; c <= UPPER_BOUND; c++) { // c is the used as the ascii
if (c < LOWER_BOUND || c >= UPPER_BOUND) //1-33 or 127 print .
row[d++] = '.';
else
row[d++] = c;
if (d == 8) { // when d = 8, we have an entire row
row[d] = '\0';
printf("%s\n", row);
d = 0;
}
}
return 0;
}
allFiles: ascii.c
gcc -Wall ascii.c -o ascii.out -lm
clean:
rm *.o
rm *.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment