Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programing: Function Requirements: In the source file you must implement the following functions. You may implement any auxiliary functions you need to make these

C programing:

Function Requirements:

In the source file you must implement the following functions. You may implement any auxiliary functions you need to make these work, as well. Please be sure the spelling, capitalization, and return types of your functions match these prototypes exactly.

Important note: The input file specification (input file given below at the end) gives certain restrictions on the strings youll have to process from those input files. Namely, strings in the input file are limited to 1023 characters and are always alphanumeric strings with no spaces or other non-alphanumeric characters. Those restrictions are designed to make your processInputFile()function more manageable, and only apply when reading from an input file. Those restrictions do not apply when we call your functions in unit testing. For example, we could pass the string Hello, world! to your createListyString()function when we call it manually during unit testing.

int main(int argc, char **argv);

Description: You have to write a main() function for this program. It should only do the following three things: (1) capture the name of an input file (passed as a command line argument), (2) call the processInputFile() function (passing it the name of the input file to be processed), and (3) return zero.

Returns: 0 (zero).

int processInputFile(char *filename);

Description: Read and process the input file (whose name is specified by the string filename) according to the description above in Section 2, Input Files. To perform the string manipulations described in that section, you should call the corresponding required functions listed below. In the event that a bad filename is passed to this function (i.e., the specified file does not exist), this function should simply return 1 without producing any output.

Output: This function should only produce output if the input file has ? and/or ! commands. For details, see Section 2 (Input Files), or refer to the input/output files included with this assignment. Note that this function should not produce any output if the input file does not exist.

Returns: If the specified input file does not exist, return 1. Otherwise, return 0.

ListyString *createListyString(char *str);

Description: Convert str to a ListyString by first dynamically allocating a new ListyString struct, and then converting str to a linked list string whose head node will be stored inside that ListyString struct. Be sure to update the length member of your new ListyString, as well.

Special Considerations: str may contain any number of characters, and it may contain non- alphanumeric characters. If str is NULL or an empty string (), simply return a new

ListyStringwhose head is initialized to NULL and whose length is initialized to zero.

Runtime Requirement: This should be an O(k) function, where k is the length of str.

Returns: A pointer to the new ListyString. Ideally, this function would return NULL if any calls to malloc() failed, but I do not intend to test your code in an environment where malloc()would fail, so you are not required to check whether malloc() returns NULL.

ListyString *destroyListyString(ListyString *listy);

Description: Free any dynamically allocated memory associated with the ListyString and return NULL. Be sure to avoid segmentation faults in the event that listy or listy->head are NULL.

Returns: NULL.

ListyString *cloneListyString(ListyString *listy);

Description: Using dynamic memory allocation, create and return a new copy of listy. Note that you should create an entirely new copy of the linked list contained within listy. (That is, you should not just set your new ListyStrings head pointer equal to listyhead.) The exception here is that if listy->head is equal to NULL, you should indeed create a new ListyStruct whose headmember is initialized to NULLand whose length member is initialized to zero. If listy is NULL, this function should simply return NULL.

Runtime Requirement: The runtime of this function should be no worse than O(n), where n is the length of the ListyString.

Returns: A pointer to the new ListyString. If the listypointer passed to this function is NULL, simply return NULL.

void replaceChar(ListyString *listy, char key, char *str);

Description: This function takes a ListyString (listy) and replaces all instances of a certain character (key) with the specified string (str). If str is NULLor the empty string (), this function simply removes all instances of key from the linked list. If key does not occur anywhere in the linked list, the list remains unchanged. If listy is NULL, or if listy->head is NULL, simply return.

Important Note: Be sure to update the length member of the ListyString as appropriate.

Runtime Requirement: The runtime of this function should be no worse than O(n + km), where n is the length of the ListyString, k is the number of times key occurs in the ListyString, and m is the length of str.

Returns: Nothing. This is a void function.

void reverseListyString(ListyString *listy);

Description: Reverse the linked list contained within listy. Be careful to guard against

segfaults in the cases where listy is NULL or listy->headis NULL.

Runtime Consideration: Ideally, this function should be O(n), where n is the length of the ListyString. Note that if you repeatedly remove the tail of listys linked list and insert it at the tail of a new linked list using a slow tail insertion function, that could devolve into an O(n2) approach to solving this problem.

Returns: Nothing. This is a void function.

ListyString *listyCat(ListyString *listy, char *str);

Description: Concatenate str to the end of the linked list string inside listy. If str is either NULL or the empty string (), then listy should remain unchanged. Be sure to update the lengthmember of listy as appropriate.

Special Considerations: If listy is NULLand str is a non-empty string, then this function should create a new ListyString that represents the string str. If listy is NULLand str is NULL, this function should simply return NULL. If listy is NULLand str is a non-NULL empty string (), then this function should return a ListyString whose headmember has been initialized to NULLand whose length member has been initialized to zero.

Runtime Requirement: The runtime of this function must be no worse than O(n+m), where n is the length of listy and m is the length of str.

Returns: If this function caused the creation of a new ListyString, return a pointer to that new ListyString. If one of the special considerations above requires that a NULL pointer be returned, then do so. Otherwise, return listy.

int listyCmp(ListyString *listy1, ListyString *listy2);

Description: Compare the two ListyStrings. Return 0 (zero) if they represent equivalent strings. Otherwise, return any non-zero integer of your choosing. Note that the following are not considered equivalent: (1) a NULLListyString pointer and (2) a non-NULLListyString pointer in which the headmember is set to NULL (or, equivalently, the length member is set to zero). For the purposes of this particular function, (2) represents an empty string, but (1) does not. Two NULLpointers are considered equivalent, and two empty strings are considered equivalent, but a NULL pointer is not equivalent to an empty string.

Runtime Requirement: The runtime of this function must be no worse than O(n+m), where n is the length of listy1 and m is the length of listy2.

Returns: 0 (zero) if the ListyStrings represent equivalent strings; otherwise, return any integer other than zero.

 int listyLength(ListyString *listy); 

Description: Return the length of the ListyString (i.e., the length of listys linked list).

Runtime Requirement: The runtime of this function must be O(1).

Returns: The length of the string (i.e., the length of the linked list contained within listy). Iflisty is NULL, return -1. If listy is non-NULL, but listy->head is NULL, return zero.

 void printListyString(ListyString *listy); 

Description: Print the string stored in listy, followed by a newline character, . If listy isNULL, or if listy represents an empty string, simply print (empty string) (without the quotes), follow by a newline character, .

Returns: Nothing. This is a void function.

The input file:

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions

Question

1. Effort is important.

Answered: 1 week ago

Question

Differentiate the function. r(z) = 2-8 - 21/2 r'(z) =

Answered: 1 week ago