Hi i am trying to create a c++ program that asks for an input and determines if it is a question or not by searching each word from the input across a database (txtfile)..... so far I have managed to make it search the database for the word but it only works on one word.... i would like to be able for it to search every word on the input seperatly.. is there a way to do this as I am really struggling...
int main(int argc, char *argv[])
{
string input1, input2;//declaring inputs
getline(cin, input1);//getting input1
input2 = "question." + input1;//giving input2 the value of input1 plus adding a "question." to the beggining
ifstream getfile;//loading the file
getfile.open("database.txt");//loading the file
if(!getfile.is_open()){
cout << "\nFile doesn't exist\n";//anouncing if the file doesnt exist
exit(EXIT_FAILURE);
}
int discovery = 0;//setting a variable for if the word has been discovered
char word[50];
getfile >> word;
while(getfile.good()){
if(word == input2)//if the database has been found announce its discovery
{
cout << "\nThe database has found " << input1 << endl << endl;
discovery = 1;
}
getfile >> word;
}
if (discovery == 0){//announces if the words wasnt discovered
cout << "\nThe database hasn't found " << input1 << endl << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
but i want it to be so you don't have to put a question mark on... is there any way that i can pick out certain words out of a variable or move each word into part of an array?.... for example the variable is "what is the day" and i can pick out the "what" and search it on the database?
int main(int argc, char *argv[])
{
int relatewords = 0;
char input1[255];
cout << "\n\nEnter the sentence for testing: ";
cin.getline(input1,255);
string wordstore[30];
int wordcount = 0;
int i = 0;
int prev = i - 1;
int beg = -1;
int end = 0;
int calcpos = 0;
int calcposcnt = 0;
while(input1[i])//while an input character exists
{
if(input1[i] == ' ')//if there is a space continue
{
if(input1[prev] != ' ')//if the previus character isnt a blank or space
{
beg = beg -2; //bug fix for beggining
while((input1[beg] == ' ') || (input1[beg] == 0))
{
beg = beg + 1;
}
calcpos = beg;//setting the calculator possition to the beggining of the word
end = i - 1;//bug fix for end
calcposcnt = 0;//resets the letter count
while(calcpos <= end)//calculates length of word
{
wordstore[wordcount] = wordstore[wordcount] + input1[calcpos];// adds the word to an array
calcposcnt++;//counts up 1 digit
calcpos++ ;//moves to the next digit on the word
}
}
prev = i - 1;