hey guys;
i have program that i should get string input from the user check if it is in the array if not store the string in it and if it already in the array i should count the number times the string. for example in this string:
"i'm the one, i'm the man "
#include<iostream>
#include<string>
#include<iomanip>
usingnamespace std;
struct Word
{
string words;
int amounts;
};
void readData(Word wordsarray[], int& size);
int main () {
int max = 100;
int size = 0;
Word wordsarray [max];
readData( wordsarray,size );
int j= 0;
while(j < size)
{
cout<< wordsarray[j].words <<" :" ;
cout<< wordsarray[j].amounts<< endl;
++j;
}
}
// read data, store a new word into an array if
//the word is already in the array i increase the
void readData(Word wordsarray[], int& size)
{
Word temp;
cout << "enter a word"<< endl;
while(temp.words != "#")
{
cin >> temp.words;
temp.amounts = 0;
// check if there is the given word in the array
if( temp.words == wordsarray[size].words.find(temp.words))
{
++temp.amounts;
cout<<"i m in the if cond"<< endl;
}
wordsarray[size]= temp;// if there is not we stored the given word
++size;
cout<<"i m out the if cond"<< endl;
}
}
i m problem is at the line 43 the if condition i m stuck here i need some help
thank for your help
You should use char[] instead of string for the userinput, and then use
someting as find() to find the spaces and seperate the input in different words.
When the userinput is stored in a string, only the first word is stored: