Here is a solution in plain and simple C++ code with no fancy function, use DMA to allocate a dynamic string array, and put data in array till you find a open space. please refer code below with comments. I hope it helps.
#include<bits/stdc++.h>
using namespace std;
int main()
{
string data="hello there how are you"; // a_size=5, char count =23
//getline(cin,data);
int count=0; // initialize a count to count total number of spaces in string.
int len=data.length();
for (int i = 0; i < (int)data.length(); ++i)
{
if(data[i]==' ')
{
++count;
}
}
//declare a string array +1 greater than the size
// num of space in string.
string* str = new string[count+1];
int i, start=0;
for (int index=0; index<count+1; ++index) // index array to increment index of string array and feed data.
{ string temp="";
for ( i = start; i <len; ++i)
{
if(data[i]!=' ') //increment temp stored word till you find a space.
{
temp=temp+data[i];
}else{
start=i+1; // increment i counter to next to the space
break;
}
}str[index]=temp;
}
//print data
for (int i = 0; i < count+1; ++i)
{
cout<<str[i]<<" ";
}
return 0;
}