Question 3 : Dynamic Memory Allocation ... 10 points For this question you will write code for the following function: c
Posted: Sun May 15, 2022 8:44 am
Question 3 : Dynamic Memory Allocation ... 10 points For this question you will write code for the following function: char* onlyDigits (char *str) This function returns a dynamically created new string which contains only the digits from the given string. Some examples: onlyDigits("(210)555-1337") should return a new string 2105551337". onlyDigits("pi = 3.14159...") should return a new string 314159". onlyDigits("HelloWorld") should return a new string *** Make sure the new string has exactly enough size to store the digits in a string (i.e., don't malloc more memory than you need). If your malloc fails, your function should call erit(-1). The only functions you should call are malloc, sizeof, erit, is Digit, and strlen. char* onlyDigits (char *str) { 1/Declare variables 1/Find the number of digits (Hint: use a loop) //Malloc and fill string //Return your string }