ECE 209 Assignment 3

Due date

This assignment must be submitted as a C single file for Assignment 3 of the ECE 209.602 section on UNCA moodle by 11:45 PM on Friday, 16 October.

Your program should be written in standard ANSI C.

The Task

Write a problem that reads a series of input lines on standard input.

Test if the input line has seven or ten alphanumeric charaters (lower case letters, upper case letters, or digits) after whitespace is ignored. If the input line does not pass this test, print out the message "Please enter acceptable input". If the input line passes the test, translate the seven or ten alphanumeric characters into digits using the encoding seen on cell phone keyboards and print it using hypens in the appropriate positions. For example, "US route 421" would be translated to "877-688-3421"; and "Brevard", to "273-8273".

Sample input and output

  US   route  431 
  US route #431
Please enter acceptable input
 My next line will be blank!
Please enter acceptable input

Please enter acceptable input
 Not Hyphens
Please enter acceptable input


Use getchar to read the input one character at a time. Test if the next character is '\n' to see if you are at the end of a line and is EOF see if you are at the end-of-file.

You do not need to store the entire input line. At most you need to store the first ten non-blank characters in an array.

Use the ctype.h routines (pages 228 to 230 of the textbook) to test if the characters are letter, digits, or whitespace.

Consider using an array or a function to map the letters into the appropriate digits.

The hints file