//C++
Given a string S containing a number of substrings separated by spaces. Write a program to do the following:
Hint: use strtok function.
#include <iostream>
#include <bits/stdc++.h>
#include <cstring>
using namespace std;
int main() {
char S[] = "Apple Mango Orange Kiwi Watermelon Banana";
char delim[] = " ";
char *token = strtok(S,delim);
vector<char *> arr;
int count = 0;
while(token) {
count++;
arr.push_back(token);
token = strtok(NULL,delim);
}
cout<<"Number of substrings: "<<count<<endl;
return 0;
}
Output screenshot
Get Answers For Free
Most questions answered within 1 hours.