Question: Extract words from lines of text Implement a function with the following declaration: int next_word(const char line[], char word[], int size); This function receives three

Extract words from lines of text

Implement a function with the following declaration: int next_word(const char line[], char word[], int size);

This function receives three parameters: line[], a C string ending in \" '; word[], a C string, consisting of characters that are not whitespace (spaces, tabs, newlines, etc.), to be extracted from line[]; and size, the maximum number of characters that can be copied into word[]. The function should copy characters one-by-one from line[] into word[], stopping at whitespace, punctuation characters (e.g. ., 3, [) or after writing size characters (remember that valid C strings must end in \\0).

If the function is invoked again with the same line[] parameter, it should extract the next word from the line. In other words, the function should resume copying where the last copy stopped. If the function is invoked with a new line[] parameter, it should start copying from the beginning of the line.

The function should return 1 if some characters were copied and 0 if no characters were copied and the end of line[] was reached.

You may use the functions isspace() and ispunct() from ctype.h to determine if a character is whitespace.

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 Programming Questions!