C Practice Practicum 2


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:

Run the unit tests. (To get full credit your code must pass the unit tests and instructor code inspection):

High Level Function Summaries

All library functions provided with the C compiler are allowed.
Refer to the function header comments for the precise requirements for each function.

get_pointer_at_position get_y_values get_sum_and_free_space same_array
  • This simply compares two pointer values and returns a 1 if the are the same.
  • It returns 0 if either pointer is NULL or if they do not point to the same memory location.

  • bool_flip_flop
  • This function alternates between returning 1 and returning 0 on successive calls to this function.
  • It returns 1 the first time, 0 the second time, 1 the third time, 0 the fourth time etc.

  • fix_bad_code
  • If the passed string is not NULL and is not empty it changes the last character in the string to a 'Z' and returns a 1.
  • If the passed string is NULL or is empty it returns a 0.
  • Be sure to check for correct handling of null pointers when correcting this code.
  • In the practicum I expect I will be manually inspecting your corrections as well as running the unit tests.
  • Activity Journal

    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.


    Practicum grading is typically:


    1. The static keyword changes what would be a local stack data declaration to permanent storage that is initialized only once.

    2. When static isused with a data declaration outside a function it prevents the data from been accessed from outside that source file.
    3. Arrays can be declared with an explicit size:
      char buffer[MAXSIZE+1] ;
        // hold a string of at most MAXSIZE characters + terminating NUL ('\0')

    4. 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

    5. 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.

    6. Pointer variables (of the appropriate type) can be point to an array declaration:
      char *pmesg = mesg ;    // *pmesg == mesg[0] == *mesg == 'H'

    7. Pointers can be dereferenced to get or set the value they point to:
      char ch ;
      ch = *pmesg ;  // ch == 'H'
    8. Pointers can be indexed like arrays  (rarely done but useful at times):
      ch = pmesg[4] ;  // ch == 'o'

    9. 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')

    10. Pointer difference gives the "distance" in underlying type units between two pointers:
      int dist = 0 ;
      dist = pnew - pmesg ;  // dist == 4

    11. ++ and -- work on pointers, adjusting them by the size of the underlying type:
      p++ ;           // increment p; points to the next character
      q-- ;           // decrement q; points to the previous character
      dist = q - p ;  // dist == 2
    12. 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]