Due: Thursday, April 23 2026, 11:59 pm

Part I: File I/O, Strings, and Signal-Handling in C

Tasks

  1. The purpose of this task is to let you have some experience on File I/O in the C language. You are expected to implement a word counter that is able to count the number of occurrences of every word in a text file. The basic requirements are as follows.

    1. The word counter should be case-insensitive. For example, there are two occurrences of the word, "the", in the sentence, "The events in question occurred in the early days of my association with Holmes.".
    2. The word counter should be able to ignore the punctuation. For instance, "Holmes." and "Holmes," should be counted as "Holmes".
    3. The word counter should read the filename from the command line.
    4. The word counter should print out the top 20 words in terms of the word frequency in descending order.
    5. You must use your linked list implemented in Task 1 of Project 5 to implement the word counter.
    6. Use this file to test your word counter. Your output should look like
          the	17
           of	7
          and	6
          was	5
           in	4
         with	4
            a	3
      windows	3
       broken	2
        wings	2
      central	2
      portion	2
          had	2
         been	2
          but	2
           up	2
         were	2
        these	1
      blocked	1
       wooden	1
      

      It's okay if words with the same frequency are displayed in a different order.

    In your report, include a screenshot of your output and illustrate how you implement the above requirements a, b, c, and d.

  2. For this task, you will create examples of signal handling in C. This task should be part of the C semantics project. But the semantics project is very long already. So, this error-handling part has been moved to this project.

    First, read the man pages on the signal package. In the terminal, you can use man to get the signal man pages.

    man 3 signal
    
    1. Write a program that can respond to a ctrl-C (interrupt). Your main function should use the signal function to set up a handler for the SIGINT signal and then enter an infinite loop. Your handler function just needs to print out a message (e.g. "Interrupted!") and then call exit();

      Include a screenshot of your output to your repot.

    2. Write a program that can handle a floating point exception. Your main function should use the signal function to set up a handler for the SIGFPE signal then do something inappropriate with floating point values, such as dividing by zero. See if you can continue the program's execution after the exception takes place.

      Include a screenshot of your output to your repot.

    3. Write a program that can handle a segmentation fault error. Your main function should set up a handler for the SIGSEGV signal then execute code that results in a segmentation fault (access illegal memory). Your handler should print something appropriate and exit.

      Include a screenshot of your output to your repot.

Part II: File I/O and Error-Handling in Selected Language

Tasks

  1. Repeat the word-frequency task from part 1 in your selected language. Make use of built-in data types (like a dictionary), if possible, to make the task easier. Include a screenshot of your testing result for the word counter in your report.

  2. On Google Sites, show how the selected language is able to read from and write to a file. If possible, you can use the above word counter in the selected language as an example. Otherwise, please give a short sample code to demonstrate.

    • How do you open, close, and read from a (text) file? Is there support for binary files?
    • Does your language have built-in support for I/O, or is it part of a set of standard libraries?
    • Does your language support opening web locations (URLs) as well as files on the local disk?
    • Can the user input information into the program interactively?
  3. Show how the language supports error handling on Google Sites. Are there built-in programming structures like try-catch blocks? Give examples that handle several different types of exceptions. You may want to integrate some of this discussion with the file I/O examples. If your language has no specific error handling support, explain if there are any conventions for handling and communicating errors.

Extensions

  1. Give examples of how a second selected language handles strings. Are there built-in string operations? Are Strings a special type? How would you split a string on spaces or other characters? Is there anything analogous to the Java toString function that a programmer can use to override the default string conversion? You are encouraged to pick the second language from List B or C.
  2. Make your word counter more robust so that it is able to handle words of arbitrary length. Test it with a word with 1001 characters in it.
  3. Implement the word counter in a second selected language (not the one used for the required tasks).
  4. Write a compilable haiku on error-handling, strings, or file I/O in your selected language. Be sure the code is an integral part of the poem (i.e. your program should not just print out a poem).

Please note that it is your responsibility to explicitly indicate the extensions you have taken. If you take the extension in C, please indicate explicitly in the codes and README file. If you take the extensions in the selected languages, please indicate explicitly in your Google Sites report or source codes and README.

Submission

The submission of this project has two components:

  1. Create a folder named Project6_<username> Place the required files into it, zip it, and upload it to the Google Classroom.

    Required Files:

    1. Code: Create a fold for each language, including C and your selected language(s). Place all of your C code and selected language programs to corresponding folders. It should be clear which files correspond to which tasks. All these language folders should be placed into the Project6_<username> folder. Note that the quality of your comments counts toward your grade.
    2. README: We use markdown files for README files. Markdown files are files with the .md filename extension. Each project should have a README file along with all your source codes. The README file will contain:
      • Project identifier, your name, and the submission date.
      • The URL of your Google Sites report.
      • The directory layout for your hand-in folder. You can use the Unix tree command to generate this.
      • Your operating system and C compiler (e.g. use gcc --version).
      • For each task, include how to compile your program, how to run your program, known bugs if there is any, and the program output (a screenshot). The screenshot should include the actual output of running the program if the output is no more than 100 lines. Otherwise, give a brief version of the output.
      • Text and images reporting on the C part of the project.
      • A description of each extension you undertook (for the C part of the project).

      You can follow the instructions for the README file from Project 1.

  2. Please do NOT include: Executable files. On Windows, these have the .exe extension. On Mac and Linux, there is no e xtension. We have found that graders often have difficulty downloading submissions if they contain executable files.

  3. Google Sites Report: The report of this project should have the following elements.
    • Title of the project and your name
    • A section for each task of part II. Every section should contain the snapshot of your sample programs, the outputs, and your explanations.
    • If you complete extensions in your selected language, please include a section for each extension, providing sample programs, outputs, and explanations.

    To check whether you've made your report well organized, please follow the Organization part in the Google Sites section in this writing page. Remember to publish all your changes and include the homepage link of your CS333 Google Sites in the README file.

© 2026 Ying Li. Page last modified: .