Question: In C++ #include #include #include using namespace std; //split function that will take a string , a delimiter , array and array size and split

In C++

In C++ #include #include #include using namespace std; //split function that will

#include #include #include

using namespace std;

//split function that will take a string , a delimiter , array and array size and split the text int split(string s, char delim,string* arr , int n ) { //finding the size of the string int len = s.length(); //i is for looping in string and arrpointer for inserting in array int i =0, arrpointer =0; //this will store the string after each delimiter string s1 = ""; //loop unless you reach end of string or the array is full while(i!=len&&(arrpointer!=n)) { //if any delimitter is encountered if(s[i]==delim) { //if the string is not empty then insert it and increase array pointer if(s1!="") { arr[arrpointer]=s1; arrpointer++; s1 = ""; } } //else just add it to the substring else{ s1+=s[i]; } //if it is at last then include that word if(i==len-1) { if(s1!="") { arr[arrpointer]=s1; arrpointer++; s1 = ""; } } i++;//increment i } // end of string is not reached and array capacity becomes max if(i!=len&&arrpointer==n) { return -1; } else { return arrpointer; } }

int main() { string arr[5]; char delim ; string s ; //taking inputs from user cout>s; cout>delim //calling function int n = split(s,delim,arr,5); cout

return 0; }

This is the code, but there are Syntax Errors I hope you can find them:

__tester__.cpp: In function int main(): __tester__.cpp:79:4: error: expected ; before int int n = split(s,delim,arr,5); ^ __tester__.cpp:80:29: error: n was not declared in this scope cout 

When you're processing data, it's useful to break up a text string into pieces using a delimiter. Write a function split that takes and split a string on a delimiter, then it populates the array of strings with the split pieces up to the provided maximum number of pieces. Function specifications: The function name: split The function parameters (in this order): o The string to be split. o A separator, character, which marks where the string should be split up An array of string, where the split-apart string pieces will be stored o The size of the array, int The function returns the number of pieces the string was split into as an integer. Your function does not print anything. Important considerations: If the string is split into more pieces than the size of the array, then the function returns -1. If the delimiter character is not found, then the function returns 1 and the entire string is placed in the array as the first element. You can assume: 1. There will not be consecutive delimiters 2. The delimiter will not be the first or the last character in the string For example: string words [10]; split("cow/chicken/fish", '/', words, 10); would return 3 and fill the array with "Cow", "chicken", "fish". Answer: (penalty regime: 0 %) Reset answer 1 1/ Put only the functions. 2 \// If you put int main({ ... }, it will say an error: redefinition of int main()

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