Question
C++ ONLY The split function from Homework 5 was such a blast, lets do it again, but with an array this time! Write a new
C++ ONLY
The split function from Homework 5 was such a blast, lets do it again, but with an array this time! Write a new function split which takes four input arguments: a string to be split, a character to split on (a delimiter), an array of strings to fill with the split pieces of the input string, and an integer representing the maximum number of split string pieces. The function will split the input string in to pieces separated by the delimiter, and populate the array of strings with the split pieces up to the provided maximum number of pieces. Your function will return the number of pieces the string was split into.
-
Your function should be named split
-
Your function takes four input arguments:
-
The string to be split.
-
A delimiter character, which marks where the above string should be split up.
-
An array of string, which you will use to store the split-apart string pieces.
-
The int length of the given array
-
-
Your function returns the number of pieces the input string was split into as an integer.
-
Your function does not print anything.
-
If the input string is split into more pieces than the array of string can hold (more than the indicated length), your function should fill only as many words as it can, and return -1.
string words[10]; split("cow/chicken/fish", '/', words[], size );
would return the count of 3 and fill the array with "cow", "chicken", "fish".
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