CSC231 Final Exam 2017

From dftwiki3
Revision as of 15:31, 29 April 2017 by Thiebaut (talk | contribs)
Jump to: navigation, search

--D. Thiebaut (talk) 16:23, 29 April 2017 (EDT)


<onlydft>

This exam is due on Dec 22nd, at 4:00 p.m..
This exam is given under the rules of the honor code. You have access to all your notes, to books, and to the Web. You cannot, however, discuss the details of the exam with anybody other than your instructor. Questions regarding the exam can only be asked in class, or using Piazza. Do not post code on Piazza. Do not suggest or imply possible solutions in your posts on Piazza. All three problems are worth the same number of points.



Problem 1: C Programming


Write a C program called 231grep.c that works similarly to the Linux grep command. Your program should get its input from the command line, just like grep, and support the "-i" switch. When the user uses this switch, the search is not case sensitive. When the user omits the switch the search is case-sensitive.
Here is an example illustrating how your program should work.

  • Create a text file called quote.txt containing the following 3 lines:


Believe in yourself! Have faith in your abilities! 
Without a humble but reasonable confidence in your own powers 
you cannot be successful or happy. --Norman Vincent Peale
  • Run grep and search for various words in the file:
231b@aurora ~/handout $ ./231grep in quote.txt
Believe in yourself! Have faith in your abilities! 
Without a humble but reasonable confidence in your own powers 
you cannot be successful or happy. --Norman Vincent Peale
231b@aurora ~/handout $ ./231grep faith quote.txt
Believe in yourself! Have faith in your abilities! 
231b@aurora ~/handout $ ./231grep Faith quote.txt
231b@aurora ~/handout $ ./231grep but quote.txt 
Without a humble but reasonable confidence in your own powers 
231b@aurora ~/handout $ ./231grep -i believe quote.txt 
Believe in yourself! Have faith in your abilities! 
231b@aurora ~/handout $ ./231grep confidence doesnotexist.txt
grep: doesnotexist.txt: No such file or directory


  • Your program should behave exactly the same way.


Implementation Details


  • Your program needs to support only the "-i" switch
  • The order of the command-line parameters will always be
  1. switch (if present)
  2. word
  3. file name


Testing


  • Your program will be tested by comparing its output to the output of grep, using diff.
  • You know enough to be able to create your own test script that should be able to inform you of whether your program's output is correct or not.


Submission


  • Submit your code on Moodle, in the grep section of the final exam.

<onlydft>