Split String by given a specific pattern is the common operation for string manipulation. In python code, you can write below code to use it conveniently.
str = 'helloabcworldabc!!'
str.split('abc') # str == ['hello', 'world', '!!']
However, in this problem, you are asked to implement split function by yourself
In this problem, you are asked to design two functions
1.
char **split_str_by_pattern(char* str, char* pattern, int* split_num);
implement split string function by given input string and pattern, then malloc a 2d char array to store the split result and return it. (also set correct split_num)
2.
void free_result(char **result, int split_num);
Free the memory space of your array that was previously allocated by using malloc. Be careful about the memory uage of your program allocated dynamically so as to avoid MLE.
The two functions have been declared in function.h, and you are asked to complete the function definitions in function.c.
Note: for OJ submission:
Step 1. Submit only your function.c into the submission block. (Please choose C compiler)
Step 2. Check the results and debug your program if necessary.
hint: you can use strlen function to get the lenght of input string (already include header file in main.c)
char s[15] = "Hello World";
printf("%d\n",strlen(s)); // 11
S_input
S_p
S_input: The input string should be splited , 20 <= S_input < 500
S_p: The pattern string , 1 <= S_p < 10
output the strings splited by given pattern. (followed by a newline character at the end of each output string)