As in the previous recitations/hw, first you need to get some already implemented programs from the textbook. Specifically, get all the files under 09-Efficiency-and-ADTs from the class web page. You can get all by simply following the link "programs from the textbook" and then go to 00-zip-files and get 09-Efficiency-and-ADTs.zip and unzip it under directory X. I assume that you already got the booklib and installed it under directory X, as we described in previous recitations (if not, please follows the instructions at the end of this recitation to get booklib and 09-Efficiency-and-ADTs and save them under directory X)

Then go to 09-Efficiency-and-ADTs, and simply say make to compile editor.c program with different implementation of buffer ADT. Then run editor program.

After compiling/testing existing client/diver program called array-editor, stack-editor, and list-editor that uses different implementations of buffer ADT, you need to implement the following functions under single linked list in listbuf.c (you can try to implement them under other representations (i.e., array and stack) later at your own time).

void ReplaceCharInBuffer(bufferADT buffer, char oldch, char newch);

  • When this function is called, it should start searching from the current cursor position, looking for the next occurrence of the character oldch in the rest of the buffer.
  • If it finds it, simply replace oldch with newch. Search should leave the cursor after the last character replaced in the buffer.
  • If oldch does not occur between the cursor and the end of the buffer, then there is nothing to replace and thus search should leave the cursor unchanged (in the original place)

int SearchStrBuffer(bufferADT buffer, char* str);

  • When this function is called, it should start searching from the current cursor position, looking for the next occurrence of the string str in the rest of the buffer.
  • If it finds it, search should leave the cursor after the found string and return the value TRUE or 1
  • If the string str does not occur between the cursor and the end of the buffer, then search should leave the cursor unchanged and return FALSE or 0
  • First, you need to add the above prototypes into buffer.h.
  • Second, you need to implement them in listbuf.c
  • Third, you need to update editor.c so that you can call those functions. So include the following in editor.c:
    • If user enters: Rxy, your editor.c should call ReplaceCharInBuffer (buffer, 'x', 'y') to replace all the occurrences of character 'x' with character 'y' after the cursor.
    • If user enters: Sxyz, your editor.c should call SearchStrBuffer (buffer, "xyz") to search string "xyz" in the buffer after the cursor.

To compile new version, use the following

> make list-editor

Note: other implementations array- and stack- will not work until you implement the above functions in them too. But their implementation is not part of this recitation. You can try to implement them later in your own time....

As always, make sure you release (free) the dynamically allocated memories if you allocate any memory in your programs. So, before submitting your program, run it with valgrind to see if there is any memory leakage

Also if you need to debug your program, compile your programs with -g option and then run it with gdb and/or ddd.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.