Due: Wednesday, May 5, 2021, at 11:59pm
The purpose of this assignment is to gain some experience with C programming. In particular, in this assignment, you will:
gdb, andThis project should be done independently. If you work with a classmate make sure you create your own implementation.
The material that we have learned in lecture is not enough to complete this assignment. It is expected that you will investigate the resources and libraries mentioned in this document to learn about how to use them.
This project is meant to be fun and allow students to explore the material. As such, you may choose to implement a project of your choice that meets the following criteria:
string.hYou may choose any project you wish that fulfills the criteria listed above. These criteria lead to something the processes a text file in some way - search, sorting, or replacing text. One idea is to consider coding your own version of one of the Bash commands we have learned.
These are not the only projects available. Slightly more complicated ideas include frequency counting (for letters and words), encryption, decryption, or html generation. If you have an idea that you are unsure about, post it on Ed and the staff will take a look at it.
Your first step should be to specify your goal. You will want to focus on a small goal to start, and if you envision different options you can record them as 'stretch goals'. First create the basic features, and then enhance if you have time. When describing your essential feature be sure to specify what input is needed, and what out put is produced - your main function will use these as arguments and output.
Protip: Implement a main that gets the arguments and prints a place holder for the output (either to screen or file), and you are off to a good start.
You should head this file with your name and date.
This file must contain a description of your project, including intended behavior. You may also include design notes about the structure of your code if you wish. It is appropriate to provide citations for references, examples, or people who provided significant help.
The file must additionally include directions for compiling your code (copying the command you use to do so is good) and directions for using the project (are there any options? what are the input arguments?)
This file is worth 5 points: 3 points for handing it in, 1 point for the project description, and 1 point for your name and technical information.
.c source file (and any others required to run your project)
This portion is worth 35 points. You will recieve 15 points for submitting any project at all. You will recieve another 10 points if your project compiles and run. You will recieve 5 points if the project performs in the way described in your README, and an additional point each for the required elements described above.
There are instructions for creating this script further down on this assignment. You should follow those directions and hand in the resulting script.
This file is worth 10 points: You will recieve 4 points for handing it in, and one point each for the major activities in the exercise.
Learning how to use a debugger effectively can be a big help in
getting your programs to work (although it is no substitute for
thinking and careful programming). To encourage you to gain a basic
familiarity with gdb, you are required to do the
following:
-g
option, to include debugging information in the executable
file.script program to capture the following
console session in a text file named debug.script.gdb with your executable program as an
argument.main,
and the other at the point in your program right after
the fopen function call that opens the input
files.gdb run
command, providing appropriate arguments. main, use the appropriate gdb command
to display the contents of variable that holds the input filename. When you've done that, continue execution of the program.gdb
commands to display a backtrace showing the functions active
at the time the breakpoint was reached. gdb and exit from the script
program's shell. Save the debug.script output file
from script to turn in later.You should use gdb's basic command-line interface for
this part of the assignment, even if you use the -tui
option for your routine debugging. The full-screen -tui
interface generates a great deal of extra output in the script file,
which makes it almost impossible to read.
You should pay attention to the following guidelines for meeting performance expectations.
strncpy in <string.h>
can be used to copy \0-terminated strings; you should
not be writing loops to copy such strings one character at a
time.fgets
and strncpy instead of routines
like gets and strcpy. The safe
functions allow specification of maximum buffer or array lengths
and will not overrun adjacent memory if used properly.stderr
and continue processing any remaining files on the command
line.klaatu or the current CSE
Linux VM using gcc with the -Wall
and -std=c11 options. Since this assignment should
not need to use any unusual or system-dependent code you can
probably develop and test your code on any recent Linux
system or other system that supports a standard C
compiler. However, we will test your submissions using the CSE
systems, so you should verify your program there before the
submission deadline.stderr and
exit with an exit code of EXIT_FAILURE (defined in
<stdlib.h> -- see the description of the
exit() function).EXIT_SUCCESS (see <stdlib.h>).
This is normally done by returning this value as the int
result of the main function.As with any program you write, your code should be readable and understandable to anyone who knows C. In particular, for full credit your code must observe the following requirements.
main function
that does everything. However it should not contain tiny functions
that only contain isolated statements or code fragments instead of
dividing the program into coherent pieces. If you wish, you may
include all of your functions in a single C source file, since the
total size of this program will be fairly small. Be sure to
include appropriate function prototype declarations near the
beginning of the file so the actual function definitions can
appear in whatever order is most appropriate for presenting the
code in the remainder of the file in a logical sequence and so that
related functions are grouped together.void functions that perform an action without
returning a value. Variables of local significance like loop
counters, indices, or pointers should be given simple names
like i, k, n,
or p, and often do not require further comments.ints,
pointers, and similar things are cheap; copies of arrays and large
structs are expensive.) Don't read the input by calling a library
function to read each individual character. Read the input a line
at a time (it costs just about the same to call an I/O function to
read an entire line into a char array as it does to read a single
character). But don't overdo it. Your code should be simple and
clear, not complex containing lots of micro-optimizations that
don't matter.chmod +x to make it
executable if needed) to review your code. While this checker may
flag a few things that you wish to leave as-is, most of the things it
catches, including whitespace errors in the code, should be fixed. We
will run this style checker on your code to check for any issues that
should have been fixed. Use the discussion board or office hours if
you have questions about particular clint warnings..emacs file in your
home directory to ensure that emacs translates leading tabs to
spaces:(setq-default indent-tabs-mode nil).
stdout before
adding another step.printf can also be your friend to print values
while executing and testing the code. <stdio.h>,
<string.h>, <ctype.h>
and <stdlib.h> libraries. Use the cplusplus reference
link on the course home page to look up details about functions
and their parameters; use a good book like The C Programming
Language for background and perspective about how they are
intended to be used.
-Wall option and (if you can) the
runtime assert function (in assert.h) to
catch coding bugs and to check for things that "must happen" or
"can't happen" during execution. Don't waste time manually
searching for errors that the compiler or run-time tests could have
caught for you.Please submit your files via the Gradescope HW4 Assignment. You should submit:
debug.script file with the script
(console) output from the Debugging exercise above.README
files.
Canvas will link to Gradescope for you. If you wish to use late days, please comment on the Late Days assignment.