Is that right ??
Given a string S containing a number of substrings separated by spaces. Write a program to do the following: 1. Count the number of substrings in S and print S with extra spaces deleted. 2. Define a dynamic array of pointers (a pointer for each substring in S). 3. Save a pointer to each substring S into the array. Hint: use strtok function. #include <iostream> #include <bits/stdc++.h> #include <cstring> using namespace std; int main() { char s[] = " Hello friends Welcome to my house "; char delim[] = " "; cout << s << endl; char *token = strtok(s,delim); int count = 0; cout << "Will be --> "; // To remove spaces // And we used the pointer to point at the substrings // And to count the substrings vector<char *> arr; while(token) { count++; arr.push_back(token); cout << token << " " ; token = strtok(NULL,delim) ; } cout<< endl <<" Number of substrings: " << count << endl; return 0; }