3.c Implement a function called text2int. You function should accept as input a string variable sre and return an intege

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
correctanswer
Posts: 43759
Joined: Sat Aug 07, 2021 7:38 am

3.c Implement a function called text2int. You function should accept as input a string variable sre and return an intege

Post by correctanswer »

3 C Implement A Function Called Text2int You Function Should Accept As Input A String Variable Sre And Return An Intege 1
3 C Implement A Function Called Text2int You Function Should Accept As Input A String Variable Sre And Return An Intege 1 (34.86 KiB) Viewed 79 times
3.c Implement a function called text2int. You function should accept as input a string variable sre and return an integer. The src string will always contain a space-separated sequence of words representing number names, e.g. "one two three", "four", "five six". Your function should return an integer that contains the respective digits in sequence, e.g. 123, 4, 56 respectively. If the string is empty, then the value zero should be returned. The complete list of possible words occurring in a string is depicted in the array variable digits. Your function should assume that the input string will contain only the respective words and they will always be separated by spaces (no checks required). Your function can manipulate the original input string data, or you can use the malloc/strdup functions to allocate memory or create a string replica. char "digits[] = {["zero", "one", "two", "three", "four", "five", "so", "seven", "eight", "nine") int text2int (char "src) { //Insert code here. } Question 3 continues on next page... 7 Question 3 continued.... To better describe the required functionality for the function we provide below a sample main method and the expected output. int main() { char "arr[]=["one two three", "one", "five six", ""); for (int i=0; i<4; i++) printf("%d: %d\n", i, text2int(strup(ar)) } Output: 0:123 1:1 2:56 3:0 [9 marks] Total 25 marks
Register for solutions, replies, and use board search function. Answer Happy Forum is an archive of questions covering all technical subjects across the Internet.
Post Reply