Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions

Question

Sketch the graph of the set. {(x, y) | y > x 2 - 1}

Answered: 1 week ago