The following guidelines are expected for all homework submissions:

Problems for Assignment #5

Learning Outcomes: 1) writing programs using the C language; 2) handling string, integer, and binary representations; 3) understanding the change between 32-bit and 64-bit representations; 4) converting from decimal to binary/hexadecimal and back; and 5) learning to use the command line arguments
  1. Write a C program, dec2bin.c to convert a base-10 number to its 32-bit binary value equivalent. You may take the base-10 number in from the command line, or you may prompt the user for the number and read in her response [your option]. Your output should be a string of binary digits which correspond to the base-10 value. For example, running the program with dec2bin 65535 [or just dec2bin if asking the user] should produce the output string 00000000000000001111111111111111. Use unsigned integers.
  2. Modify your C program from problem #1 to to make the program dec2hex.c which will output the 32-bit hexidecimal value equivalent. For this modification, you must also handle an optional command line argument which indicates the number of bits that the output hex value will represent, either 32 or 64. For example, running the program with dec2hex 65535 32 [or just dec2hex 32 if asking the user] should produce the output string 0x0000FFFF. Running the program with dec2hex 65535 64 [or just dec2hex 64 will result in the output of 0x000000000000FFFF. Use unsigned integers.
  3. Write a C program timesTables.cto output the times tables from 2 to N, where N is a user-defined number take from the command line. Output the values in a nice table, using a format specifier that will allow for enough space for the results to be neatly aligned in columns.
  4. Write a C program holdit.c that times you as you hold your breath. The program must put out a short message that has instructions on what to do, which should read something like,
    "This program will time how long you can hold your breath. Take a deep breath, then press the 'Enter' key. When you absolutely have to exhale, press the enter key again. The duration will be displayed in minutes and seconds."
    You will need to research the way the time functions work in C.
  5. Write a C program wordcount.c that counts the number of words in a file of text. Your program should take a file name as a command line argument. As you read the file contents, keep a count of the number of words which are separated by "whitespace". [Research what is meant by "whitespace" in the C environment.] When the file has been completely read, close the file and write out the number of words. Be sure you handle error conditions like files that don't exist or errors while reading the file. You should also be able to handle files that are in different directories from where your program resides.