Question: // CSE240 SPRING 2023 Assignment 04 // Enter your name here #include #include #include #include // Read before you start: // You are given a
// CSE240 SPRING 2023 Assignment 04
// Enter your name here
#include
#include
#include
#include
// Read before you start:
// You are given a partially complete program. Complete the functions in order for this program to work successfully.
// All instructions are given above the required functions, please read them and follow them carefully.
// You shoud not modify the function return types or parameters.
// You can assume that all inputs are valid. Ex: If prompted for an integer, the user will input an integer.
// You can use only the strlen() of strings.h library to check string length. Do not use any other string functions
// because you are supposed to use pointers for this homework.
// DO NOT use arrays to store or to index the characters in the string
// Global Macro Values. They are used to define the size of 2D array of characters
#define NUM_STRINGS 4
#define STRING_LENGTH 50
// Forward Declarations
void initializeStrings(char[NUM_STRINGS][STRING_LENGTH]);
void printStrings(char[NUM_STRINGS][STRING_LENGTH]);
int isSorted(int *arr, int size);
void removeDuplicates(char *str);
int count_vowels(char *str);
int count_words(char *str);
int longest_palindrome(char *str);
char most_common_char(char *str);
// Use pointer 'ptr' to traverse the 2D array of characters variable 'strings' (input from user in main()) and set all characters in each
// array to a null terminator so that there is a 4 row and 50 column 2D array full of null terminators.
// The null terminator '\0' is used to denote the end of a string.
void initializeStrings(char strings[NUM_STRINGS][STRING_LENGTH])
{
char *ptr = &strings[0][0];
// TODO: Implement function using pointers
}
// Use pointer 'ptr' to traverse the 2D character array 'strings' and print each string.
void printStrings(char strings[NUM_STRINGS][STRING_LENGTH])
{
char *ptr = &strings[0][0];
// TODO: Implement function using pointers
}
// Function to check if an integer array is sorted in non-decreasing order
int isSorted(int *arr, int size)
{
// TODO: Implement function using pointers
}
// Function to remove duplicate characters from a string
void removeDuplicates(char *str)
{
// TODO: Implement function using pointers
}
// Function to count the number of vowels in a string
int count_vowels(char *str)
{
// TODO: Implement function using pointers
}
// Function to take a string as input and return the number of words in the string. Words are defined as contiguous sequences of non-space characters.The function should take a pointer to a string as input and return an integer.
int count_words(char *str)
{
// TODO: Implement function using pointers
}
// Function take a string as input and return the length of the longest palindrome that can be formed by deleting zero or more characters from the string. The function should take a pointer to a string as input and return an integer.
int longest_palindrome(char *str)
{
// TODO: Implement function using pointers
}
// Function take a string as input and returns the most common character in the string.If there are multiple characters that occur with the same highest frequency, return any one of them. The function should take a pointer to a string as input and return a char.
char most_common_char(char *str)
{
// TODO: Implement function using pointers
}
// You should study and understand how main() works.
// *** DO NOT modify it in any way ***
int main()
{
char strings[NUM_STRINGS][STRING_LENGTH]; // will store four strings each with a max length of 34
int i, key;
char input[STRING_LENGTH];
printf("CSE240 HW4: Pointers ");
initializeStrings(strings);
for (i = 0; i
{
printf("Enter a string: "); // prompt for string
fgets(input, sizeof(input), stdin); // store input string
input[strlen(input) - 1] = '\0'; // convert trailing ' ' char to '\0' (null terminator)
strcpy(strings[i], input); // copy input to 2D strings array
}
printStrings(strings);
// Test cases for each function
int arr1a[] = {1, 2, 3, 4, 5};
int arr2a[] = {1, 2, 4, 3, 5};
// Test isSorted function
int sorted1 = isSorted(arr1a, 5);
int sorted2 = isSorted(arr2a, 5);
printf("isSorted([1, 2, 3, 4, 5]): %d ", sorted1); // Expected output: 1
printf("isSorted([1, 2, 4, 3, 5]): %d ", sorted2); // Expected output: 0
// Test cases for each function
char str1b[] = "hello";
char str2b[] = "this is a test string";
// Test removeDuplicates function
removeDuplicates(str1b);
removeDuplicates(str2b);
printf("removeDuplicates('hello'): %s ", str1b); // Expected output: helo
printf("removeDuplicates('this is a test string'): %s ", str2b); // Expected output: this aerng
// Test cases for each function
char str1c[] = "hello";
char str2c[] = "this is a test string";
// Test count_vowels function
int count1 = count_vowels(str1c);
int count2 = count_vowels(str2c);
printf("count_vowels('hello'): %d ", count1); // Expected output: 2
printf("count_vowels('this is a test string'): %d ", count2); // Expected output: 5
// Test cases for each function
char str1d[] = "hello";
char str2d[] = "this is a test string";
// Test count_words function
int word_count1 = count_words(str1d);
int word_count2 = count_words(str2d);
printf("count_words('hello'): %d ", word_count1); // Expected output: 1
printf("count_words('this is a test string'): %d ", word_count2); // Expected output: 5
// Test cases for each function
char str1e[] = "hello";
char str2e[] = "this is a test string";
char str3e[] = "racecar";
// Test longest_palindrome function
int palindrome_len1 = longest_palindrome(str1e);
int palindrome_len2 = longest_palindrome(str3e);
printf("longest_palindrome('hello'): %d ", palindrome_len1); // Expected output: 2
printf("longest_palindrome('racecar'): %d ", palindrome_len2); // Expected output: 7
// Test cases for each function
char str1f[] = "hello";
char str2f[] = "This is a test string"; // Note that t in "This" is uppercase.
// Test most_common_char function
char common_char1 = most_common_char(str1f);
char common_char2 = most_common_char(str2f);
printf("most_common_char('hello'): %c ", common_char1); // Expected output: l
printf("most_common_char('This is a test string'): %c ", common_char2); // Expected output: s
return 0;
}

PLEASE HELP!!!!!!!!!!!!!!!!
Programming Exercise (100 points) 1. For this program you will complete the program in the a03p01.c file. Find the places in the code marked with the ToDo label and complete the work. You should not change any other part of the code. This includes do not add any global variable or any other function. You will be writing most functions (initializeStrings, printStrings, isSorted, removeDuplicates, count_vowels, count_words, longest_palindrome, and most_common_char) using pointer operations only, instead of using array operations. In this assignment, the arrays in all functions need to be accessed with pointers, not as array indexes. It means you cannot use an array element value through indexing like s[0][0] or s[i][j]. However, you can use the addresses of the array elements and use the pointer to access the array element value. You can find out more about these functions by reading through the instructions in the a04p01.c file. Please see the test cases in the a04p01.c file main() function and make sure that your program runs and shows the outputs same as the expected outputs defined there. Take a screenshot of the output for each function with each test case (each function have two test cases). Create a file named "a04". Create a section in this document called Program01 and paste your screenshots under this section. Mark each your test cases and their outputs, for instance, function initializeStrings() test case 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
