Question
language: C Write the file parse.c with the the following functions. Include parse.h as the header Write a function int count_tokens(char* str) that gets a
language: C
Write the file parse.c with the the following functions. Include parse.h as the header
Write a function int count_tokens(char* str) that gets a string and counts the number of tokens in str. A token is any substring separated from others by spaces. Examples: On input "ABC ) 123 !!" the function will return 4. On the input "( 8 + ( 41 - 12 ) )" the function will return 9. **You may assume that tokens are separated by a single space, and there are no spaces neither before the first token not after the last token. 2) Write a function char** get_tokens(char* str, int n_tokens) that gets a string, and the number of tokens obtained in count_tokens, and returns an array of strings, where the ith element of the array contains the ith token. Example: On input str = "( 8 + ( 41 - 12 ) )" and n_tokens = 9 the function returns the array ["(", "8", "+", "(", "41", "-", "12", ")", ")"]. ** You may assume that tokens are separated by a single space, and there are no spaces before the first token, and no spaces after the last token.
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