Fill in the code in cpractice2.c and fill out the activity journal. You will not have to do a journal on the actual practicum.
You are allowed full access to your prior work, internet searches, and all course materials.
The point of the activity journal is to help you reflect on your readiness for the practicum.
Download
cpractice2.zip. A Makefile (with gdb debug support) is included for your convenience.
You do not need to run the program itself.
Use wget and unzip in your puTTY window to accomplish downloading the files.
Run the make by simply typing make:
make
Run the unit tests. (To get full credit your code must pass the unit tests and instructor code inspection):
./test
Run the valgrind utility on your code to make sure you do not have any memory leaks:
valgrind ./test
All library functions provided with the C compiler are allowed.
Refer to the function header comments for the precise requirements for each function.
Fill out the ActivityJournal_CPractice.txt that is in the zip file and submit that with your cpractice2.c file.
Place your completed cpractice2.c and ActivityJournal_CPractice.txt files in a directory named cpractice2 at the top level of your git repo.
Arrays can be declared with an explicit size:
char buffer[MAXSIZE+1] ;
// hold a string of at most MAXSIZE characters + terminating NUL
('\0')
Arrays can be initialized, which also sets the array's size and
the initial contents:
char mesg[] = "Hello!" ; // a 7 element array - 6 characters
in Hello! + terminating NUL
An array name is a constant pointer to the first (0th)
array element; thus:
mesg
== &mesg[0] ; // address of the first character in the
message.
mesg[0] == *mesg ; // the 0th element of an array is the same
as dereferencing mesg as a pointer.
Pointer variables (of the appropriate type) can be point to an array declaration:
char *pmesg =
mesg ; // *pmesg == mesg[0] == *mesg == 'H'
Pointers can be indexed like arrays (rarely done but
useful at times):
ch = pmesg[4]
;
// ch == 'o'
Pointers can have integers added or subtracted to
generate new pointers:
char *pnew = NULL ;
pnew = pmesg + 4 ; // pnew points to the fourth character past pmesg (here, *pnew ==
'o')
Pointer difference gives the "distance" in underlying type
units between two pointers:
int dist = 0 ;
dist = pnew - pmesg ; // dist == 4
Pointer can combine both dereferencing and pointer increments and decrements in one statement:
pmesg = mesg ;
ch = *pmesg++ ; // ch == 'H' and pmesg == &mesg[1]
pnew = mesg + 4 ;
ch = *pnew-- ; // ch == 'o' and pnew == &mesg[3]
pnew = mesg ;
ch = *++pmesg ; // ch == 'e' and pmesg == &mesg[1]
pnew = mesg + 4 ;
ch = *--pnew ; // ch == 'l' and pnew == &mesg[3]