Question: 1 * * * * Expand String In this part, we define a special pattern that can be used in strings to expand the original

1****
Expand String
In this part, we define a special pattern that can be used in strings to
"expand" the original string. The format of this pattern is defined as
No (part)
where N is a one-digit number and the "part" inside of the
parentheses is the substring you want to repeat. By expanding a string
including this pattern(s), you basically need to repeat the "part" for N of
times in that string.
For exanple,
Original string: "H9*(n)"
Expanded string: "Hannannann"
Original String: "I 3*(really ) want to eat candy."
Expanded String: "I really really really want to eat candy."
Original string: "123AB2*(C)"
Expanded string: "123ABCC"
ASSUNPTIONS:
To simplify the inplenentation, you can assune:
The original string will ONLY include ONE of such pattern.
The N can only be a ONE-digit positive number, i.e.,1-9.
The three characters '*','(' and ')' are special characters. They won'T
be used as the regular content/data of a string. So whenever there is a '*',
you can assune there will be such a pattern around.
There is NO NESTED repeat patterns, i.e., a pattern inside of another
pattern.
**f
1****
(10 pts)
a.
expand_str_len
STEP 1: Estinate how much space is needed for the expanded string.
To allocate space on the heap, you have to first scan and parse the
original string and calculate the size for the new string PRECISELY.
Let's write a dedicate function expand_str_len to do this.
HINT:
Whenver finding a '*", use the character on the left as the N. Convert
this character to an int for later use.
Then find the charaters after a '*' and between '(' and ')' as the "part"
in the pattern. Calculate the length of this part and nultiply it by the number N,
then you have the size of the expanded part
in the new string.
To calculate the entire space required by the new string. A better way is
to calculate the change (or difference) between the new and original string.
When calculating this size change in the new string, you have to consider the
1 byte for the n and 3 bytes for =()=.
Given an input string, this function will parse the string and calculate the
size required for the new string.
You CAN NOT use any function fron string.h, EXCEPT for strlen();
Eparan input - the original string
ereturn neary space required by the new string.
*/
int expand_str_len(char* input){
 1**** Expand String In this part, we define a special pattern

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!