Home
Netbeans Eclipse Qt Java
Games
College of Engineering Aeronautics and Astronautics Agricultural and Biological Engineering Biomedical Engineering Chemical Engineering Civil Engineering Construction Engineering and Management Electrical and Computer Engineering Engineering Education Engineering Professional Education Environmental and Ecological Engineering Industrial Engineering Materials Engineering Mechanical Engineering Nuclear Engineering
EPICS (Engineering Projects In Community Service) First-Year Engineering Program First-Year Engineering Honors Program Global Engineering Program Minority Engineering Program Professional Practice (Co-Op) Program Women in Engineering Program
College Administration Schools Programs All Groups All People ECN Webmail
Purdue Home

ECE 264 Spring 2010

Individual Programming Assignment 1

Counting Words in a File

You should never add space or any special symbol (such as %$#) in a file's or a directory's name. The international standard for file names has no space.  If any of your submission contains a file whose name includes space or special symbol, the grading program may not work.

Assignment

You will write a program that reads in text from a file and counts the number of times a word appears in the text file.

Purpose

In this assignment, you will learn how to

  • check the number of arguments given to a C program
  • open a file and read the words
  • count the occurrences of words
  • allocate and release memory

Input Arguments

The program needs exactly one argument as the name of the input file.

Output Format

Standard output by the program are printed using stdout (on the screen).  Error messages are printed using stderr (you should use fprintf to print to stderr).

The output consists of N lines, where N is the number of distinct words in the input file.  Each line consists of a word, followed by a white space and a number indicating the number of occurrences of that word.  Words appear in the same order as they first appear in the input file.

For example, the content of a given input file is:

Good better best
Never let it rest
Till good is better
And better is best

The expected output from the program should be:

Good 1
better 3
best 2
Never 1
let 1
it 1
rest 1
Till 1
good 1
is 2
And 1

Assumptions

To simplify this assignment, you can assume

  • Every line contains at most 80 letters.
  • Every two adjacent words are separated by one and only one space.
  • No symbol or number may appear.
  • Each line starts with a word and ends with a word, i.e. no space at the beginning or the end of a line. Please be aware that a line ends with '\n' (new line character).
  • No word spans two or more lines.
  • Words are case-sensitive. "The" and "the" are treated as two different words.
  • A line may contain nothing, except the new line character '\n'. Ignore such an empty line.
  • There is no maximim number of lines that can be in an input file.

Code

A project has been created for you with a sample structure.  Please check out the code by using the following command on a UNIX shell:

svn checkout http://purdue-wl-ece264-assignment.googlecode.com/svn/trunk/2010/IPA1 purdue-wl-ece264-assignment-read-only

The project contains the following files:

  • ipa1.c  /* a C program that provides the structure of IPA1, please fill in the missing code */
  • Makefile  /* create executable and test the program, read the comments for the options */
  • README /* you need to explain how to implement the assignment */
  • sample inputs
    • input1 
    • input2 
    • input3 
    • input4 
    • input5 
    • input6

You may change anything in the provided ipa1.c or write your own.

You do not need to use Makefile to build your program for IPA1, nor is Makefile required in your IPA1 submission.  However, Makefile is required for IPA2 - 4.

Useful C Functions

Check the manual pages of these functions. They may be useful to IPA1.

  • file: fopen, fclose, fgets, fseek, feof
  • string: strcmp, strcpy, strchr
  • memory: malloc, free

Submission Procedure (Read carefully)

All programming assignments are graded by computer programs. You must meet the specifications precisely without any deviation. If your program has a different output format, you may lose most points.

Before you submit your first assignment, please go to Blackboard.  There will be an assignment that ask you to provide a passphrase, which will be used to encrypt your grade reports sent to your mail box by the grading system.  Enter a combination of letters or numbers (no white space, no special symbols) as your passphrase to the answer box and click submit.  Your grade reports will not be sent until you have provided your passphrase.  Please allow some time for the teaching staff to record your passphrase in the grading system.

Submit your program to this site.  After submission, your program will be graded automatically. You are strongly encouraged to submit early.

It is your responsibility to check whether you submitted correct files. Please double check your submission. Submitting wrong files is a common mistake.  Your programs are tested using Linux.

  • The instructor and the teaching assistant will never enter your account for grading. Do not send your password to the instructor. If you send your password, the instructor will inform ECN to disable your account.
  • The instructor and the teaching assistant will never grade on your personal computer. Do not say "I can show you on my computer."
  • The instructor and the teaching assistant will never change anything you submit.  Do not say "If you delete that line or add this file, everything works."
  • For this project, we only require you to submit the ipa1.c and the README file.  The file name of your source code must be "ipa1.c" (all lower case letters).  The README file must be named as "README" (all upper case letters).  File names in Linux are case-sensitive.  If you submit files with wrong names, they will not be recognized and you will receive zero.

Late Submissions

Each assignment is due at 10:59AM on the corresponding deadline.

  • Before the deadline, you can submit and resubmit as many times as you wish. You will receive the grading result soon after submission. If you submit multiple times, your score is the highest among all submissions.
  • The time is determined by the server's clock, not your watch.
  • You must submit early. Sometimes the Internet can be slow. If you wait until a few minutes before the deadline, it is very likely that you will miss the deadline. Another common mistake is submitting wrong files when the deadline is too close.
  • Do not send your assignment by email because it is late. Email submission is ignored.
  • Every assignment has a no-penalty extension of 5 hours. The extension is not a new deadline. The extension is provided to accommodate unexpected problems, such as slow network. The extension should be sufficient for you to come to school and submit an assignment, if your home computer breaks.
  • If Purdue cancels classes on a submission deadline, the deadline is extended to one day after classes resume.
  • If the server is down within 12 hours of the deadline, the deadline will be extended by 24 hours.
  Time Penalty
Deadline 10:59 AM D day -
Extension 3:59 PM D day -
Late Submission 3:59 PM D + 1 day 1 point
3:59 PM D + 2 day 2 points
3:59 PM D + 3 day 3 points
3:59 PM D + 4 day 4 points
after 3:59 PM D + 4 day 6 points

Q: Why is the submission deadline set to 10:59AM?  Some students are in lectures at that time.

A: If the grading server breaks, ECN may provide timely assistance to solve the problems. If you have a lecture, please submit earlier.

Q: I submit before the deadline and obtain 3 points.  I submit again the next day and obtain 5 points. What is my score?

A: Your second submission becomes 4 points due to the late penalty. Since it is higher than 3, your score is 4.

Q: If I am sick for a whole week, can I receive an extension?

A: If you provide appropriate documents showing that it is impossible to do the assignment, an extension may be granted.

Privacy and Grade Report

Purdue prohibits sending grades by email. Hence, we have to encrypt your grade report. At the beginning of the semester, you are asked to provide a passphrase to encrypt any reports sent to your Purdue mailbox.  The passphrase should be provided only once through Blackboard.

If you do not provide the passphrase, your grade is not affected but you will not receive a grade report by email. You have to wait for the teaching staff to record the grade in Blackboard.

Policy Handling Dishonest Behavior:

You will receive F in this class if you cheat. Your case will always be reported to ECE main office. There is no exception. If you help a student cheat (such as giving your code), you will also receive F. If you want to help a classmate, tell the person to talk to the instructor or the teaching assistants.   You are responsible protecting your assignments. Do not leave a computer unattended. Do not throw away the printout of your programs.

Do not copy code from your classmates or from the Internet.

You must understand that you cannot cheat forever. If you cheat, you will get caught, sooner or later.

You are allowed to use the code given to you by the instructor or generated snippets using the tools approved by the instructor. You are not allowed to download code from the Internet and claim the code as yours. If you discover useful code, you must (1) announce the code in Blackboad Discussion so that everyone in the class is aware of the code or (2) request the instructor's written approval or (3) describe with sufficient details where the code comes from and how you use it in your README file. You must request the code owner's permission to use the code and you must cite the source in your submission. You are not allowed to purchase code from, for example, getacoder.com.

There were cases when students claimed they "accidentally" submitted code from the Internet because these students were "studying" the code. In all these cases, the students were considered cheating and received appropriate penalty.  It is not possible to "accidentally" submit the code that is not written by you. If it is your code, you must have spent many hours writing the code. You will treat the code with the greatest care. You will check, double check, and check again before submission. If you have spent so much time on an assignment, you will not accidentally submit wrong code.  "Accidentally submitting wrong code" is an invalid defense and you will receive F in this class.

You should know that advanced tools are available checking programs' similarities. These tools can detect programs of similar structures, even if you rename variables or change for to while (or many other techniques to disguise). These tools have successfully detected many cheating cases.  The very fact that you consider to cheat indicates your lack of programming skills. Hence, you do not have sufficient knowledge to defeat these similarity checkers. If you need help, please talk to the instructor or the teaching assistants, or post your questions in Blackboard Discussion. Do not ask your classmate or anyone that took this course to give code to you.  The submissions from multiple semesters will be checked.

Grading (total 6 points)

This programming assignment will be graded by another program.

  • You will receive zero for functionality if your program cannot compile due to one or multiple syntax errors or other compiler/linker errors.
  • If your program compiles successfully, ten input files will be used to test your program.  You will receive 0.5 point for each input file if the output from the program is correct.
  • 0.5: README explaining how to sort the lines based on the n-th word.
  • 0.5: coding style and clarity
    • 0.1 meaningful variable names (not just i, j, k, x, y...).
    • 0.1 proper indentation.
    • 0.1 proper names (noun for variables, verb for functions).
    • 0.1 one statement per line, no overly complex statements, no line exceeds 80 characters (at least one newline every 80 characters).
    • 0.1 sufficient comments in the code.
  • Penalties (negative)
    • 0.5: for each warning message reported by compiler/linker with -Wall and -Wshadow switches enabled.
    • up to 2: if your program has memory leak (reported by valgrind). The program has to release allocated memory before the program terminates.
    • 2: if your program has one or more files that have not been closed when the program terminates (detected by valgrind).
    • Other penalties regarding submission are clearly stated on the submission page.
  • The lowest score is zero. You will not receive a negative score.

Please notice that the README and coding style categories are graded manually.  Therefore, they will not be included in the grading reports sent by the grading system.  Also, please be aware that only your latest submission will be used to grade these two categories.

Performance

The score of your program is not determined by its performance. However, your program has to be "reasonably fast" so that it can be graded. Your program cannot take longer one minute for an input file of 10,000 lines.  Otherwise the program will be terminated by the grading script.

Remote Execution

If you want to execute your programs at an ECN-Linux computer remotely, please do the following

ssh your_purdue_account@ecelinuxA.ecn.purdue.edu

A = 01 ~ 48

You can download PuTTY as an SSH client for Windows. Please go to https://engineering.purdue.edu/PULS/.

Useful Tools

The following tools are extremely useful. Each takes you only a few minutes to learn.