Question: C programming, write a function that takes a line of text and breaks it into words. The function should take three parameters: a character array
C programming, write a function that takes a line of text and breaks it into words. The function should take three parameters:
a character array that stores the line of text
an array of words or double pointer to store the words
an integer pointer to store the number of words.
For example, void towordschar line char words int numwords
In the sentence words are separated by spaces. As you go through the line of text,
if the character is not space then add it to the end of the current word
if it is a space then move to a new word
if it is a newline, processing completes
read new words in a temporary char array, then allocate exactly the amount of memory needed into the words array and copy the characters there.
End each word with a character so they can be printed as strings.
Write additional code main function to:
read the line of text with getchar into an array
Declare the array of words to store up to words
Call the function.
Print the words.
Note: Commenting Code and explain understanding
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
