Sentence to a list , need help
The idea is to create a " list " given a user inputed sentence.
For example:" Hello I am here " . WOuld output the list .
Hello
I
am
here
----------------------
I have tried to compile and I get a error , but it tells me nothing .I think it is right and should work.
----Here is the code if someone can help I would greatly appreciate it.
Code:
#include <iostream>
#include <string>
using namespace std;
void main()
{
string sentence;
char string1[]="";
char space[]=" ";
char period[]=".";
char word1[]=" ";
char word2[]=" ";
cout << "This program turns a given sentence into a list of words." << endl;
cout << "Input a sentence: ";
getline(cin, sentence);
cout << endl;
int len = sentence.length();
strcpy(string1, sentence.c_str());
int i;
int t;
for(i=0; i<len; i++)
{
if(string1[i]==space[0] || string1[i]==period[0])
{
for(t=0; t<i; t++)
{
word1[t]=string1[t];
}
break;
}
}
i=i+2;
t=t+2;
for(i; i<len; i++)
{
if(string1[i]==space[0] || string1[i]==period[0])
{
for(t; t<i; t++)
{
int b=0;
word2[b]=string1[t];
b=b+1;
}
break;
}
}
cout << endl;
cout << word1 << endl;
cout << word2 << endl;
int endProg=0;
while(endProg==0)
{
cout << "To end the program type 1: ";
cin >> endProg;
cout << endl;
}
}