Question
The programing language is C /*Code starts here NOTE: You should NOT use array notation inside your functions. Use only * pointer notation for any
The programing language is C
/*Code starts here
NOTE: You should NOT use array notation inside your functions. Use only * pointer notation for any code that you write. * */
#include #include // NO additional imports allowed. You *can* make helper functions if you wish.
#define MAX_STRING_LEN 1024
char *find_last_substring(char *str, char *a) { /* * Given a string `str` and another string `a`, return a pointer to the start * of the *LAST* occurrence of `a` in `str`. * * For instance, if we had: (here) * V * char str[MAX_STRING_LEN] = "Hello everyone, Hello world!" * char *res = find_last_substring(str, "Hello"); * * then, we would except `res` to be a pointer to the character marked above. * In particular, since the second "Hello" is at index 16, we should get * the following: * * res - str == 16; (This is pointer arithmetic) * * If `a` is not a valid substring of `str`. return NULL. */
return NULL; // Replace with correct return }
void split_vowels(char *str, char *vowels) { /* * Move all of the vowels from `str` (in the order of appearance) to the * string `vowels`. (ie, after the function call `str` should not have any * vowels in it). You may assume there is enough space allocated in `vowels`. * * Look at the test case below for an example. */
return; // Not returning anything. `str` and `vowels` modified directly. }
// ----------------------------------------------------------------------------
// Do not change the lines above and below the main function. You are free to change anything // inside the main() function itself. #ifndef __testing__ int main() { char my_str[MAX_STRING_LEN] = "many many people have many many hobbies"; char *res = find_last_substring(my_str, "many"); if (res - my_str == 27) { printf("- find_last_substring() returned the correct result! "); } else { printf("! find_last_substring() did not work properly. "); }
printf("---------------------------------------------------------------- ");
char str[MAX_STRING_LEN] = "This sentence has many vowels! AEIOU"; char vowels[MAX_STRING_LEN]; split_vowels(str, vowels);
printf("(Expected Result) str: \"Ths sntnc hs mny vwls! \", " "vowels: \"ieeeaaoeAEIOU\" "); printf("(Your Solution) str: \"%s\", vowels: \"%s\" ", str, vowels); } #endif
You don't have to do anything for the main function I just kept it here to help with testing.
Thanks for the help :)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started