ECE-1021
HOMEWORK #1
(Last Mod: 27 November 2010 21:38:39 )
Write basic functions that characterize the ASCII codes.
Generate a table of the output from these functions.
Write a program that prints a table of all of the ASCII codes with each column containing information as follows:
Integer Value (in decimal)
Character/name (name is the 2- or 3- letter abbreviation for the non-graphing characters)
Is the character is a valid ASCII character (isascii()
)
Is the character is a control character (iscntrl()
)
Is the character a printing character (isprint()
)
Is the character a graphical character (isgraph())
Is the character a white-space character (isspace()
)
Is the character a punctuation character (ispunct()
)
Is the character a decimal digit (isdigit()
)
Is the character a hexadecimal decimal (isxdigit()
)
Is the character an alphanumeric character (isalnum()
)
Is the character an alphabetic character (isalpha()
)
Is the character an uppercase character (isupper()
)
Is the character a lowercase character (islower()
)
The uppercase version of the character (toupper()
)
The lowercase version of the character (tolower()
)
In any column where the actual characters are printed - except the one containing the names - you should print a period in place of the character if the character is a non-graphical character.
The values in all but the first two and last two columns should be based on functions that return a logical value depending on the ASCII code that is passed to them. The value should be a 'T' if the function returns a logical True and should be a hyphen if it returns a logical False.
The last two columns should call functions that convert an upper case character to lower case (or vice-versa) if the character is alphabetic and returns the character unchanged if it is not alphabetic.
Each column should have a heading. The heading for the first two columns are "value" and "name" respectively. The headings for all other columns are the names of the functions used in that column (there is no need to include the parentheses that follow the function name). In order to get all of the columns to fit within the width of the screen, the names will need to be printed vertically - i.e., each succeeding line contains the next character from that column's heading.
Other than PrintHeader(), the only function from any standard library that
your code may call, either directly or indirectly, is putc()
. This means that
you may use the printc()
function defined in the C Source Code Template since
it only uses putc()
.
Your program should be well-modularized with no one function requiring more
than approximately one screen (25 lines) to display. This is not an
absolutely rigid limitation, but functions longer than that should have a
reason for being so and should be kept to the minimum length practicable. The
one function that you will find reasonable to violate this limitation on is
the one that prints out the names of the control characters. This is an ideal
situation for a switch()
statement with one case
label for each of the control characters plus the space character.
HINT: Printing the column headings is not difficult, but it is time consuming because you need to do much of it in a very brute force manner. Leave it for last. Get the table printing out correctly and formatted properly and then add in the column headings.