Adaptive Dictionary

how do you add a string to one of the strings that are empty in a array of strings.
The purpose of this project is to add new words being found in a message.
I did good up until where i have to add a string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 //scroll all the way down till you see the lines of code in red... I do not know what string //function to use to add it to the adaptive dictionary..  I was trying to say for every time 
//bool found =false add the string to the array of strings in an open dictionary( i).
//adaptive dictionary
//michael harootoonyan
//cs02_lab4_#4
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string input = "the quick brown fox died in the street";//array char's
	string dictionary[100];//array of strings
	dictionary[0] = "the";//doesnt have to be 0 can be 1 2 3 99 98 doesnt matter just dont overload a variable
	dictionary[3] = "fox";//reason why these are labeled are for testing purposes
	dictionary[1] = "quick";//read above line
	string temp = "";//this was made to reset the value of strings being added.

	string output = "";//this needs to output a code like after i delete "the"  "fox" "quick" declarations later "x 0 xyx 1"
	for (int i = 0; i != input.length(); i++)//note:input.length()-1 the minus one is because we over run the array so if i was less than or eqaul to remember to use the minus 1

	{
		if (input[i] != ' ')//as we scan looking for objects that are not the character space
		{
			temp += input[i];//we append whats in the input to the temp string withoutany spaces
			//cout << i << " " << input[i] << endl;//print out the iteration , space , word ,then new line//itll print twice if i did not add //
			//this cout line in this statement just helps tests to see if what i did for my if statement works correctly. i should test my things
			//as i go through my code to make sure i didnt introduce any logic bugs.
		}
		//if this is the end of the word.//this is just to make sure that every word is accounted for in every circumstance remaining.
		if (input[i] == ' ' || i == input.length() - 1)//if one of the characters is a space or the end of a word..
			//last printable character is the reason why we do input.length()-1 for the ==
			//if statements use == cause there constants//if it was i! ==input.length() -1 that would print until fo it won't print fox.
		{
			cout << "temp=" << temp << endl;//this is why its printing twice//this line guides me saying what strings of characters are
		//temp has already been taken care of in the above if statement...but the difference is it will print temp=(the new word identified). 
			bool found = false;//the dictionary is going to be made as it grows so its not going to be there 
			// so we must assume that its not in tehre thats why we do bool found= false /type bool//variable name=found// false (prints out 0)
			for (int c = 0; c != 100; c++)//for 0 through 99
			{//the if statement below takes the dictionary of strings compares to the temp string and says if they are equal to eachother
				//the dictionary[c].compare is the case where the word is found then print iteration,space,the word in dictionary,end line;
				if (dictionary[c].compare(temp) == 0)//if (str1.compare(str2) != 0)
				{
					found = true;//prints a 1 for true boolean logic.
					cout << c << " " << dictionary[c] << endl;//prints iterations,space,the word in the dictionary if it exists
				}
		}//but if its false and 
			if (found == false)//if the word is not in the dictionary
			{
				for (int z = 0; z != 100; z++)//reason why we are using the 100 is because now were begining to store strings of characters from 0to99.
				{
					if (dictionary[z].length() == 0)//the zero means if the length of any of the strings is 0 so like this temp="" add a string of chars to it
					{
						dictionary[z] = temp;//if its true if its found in dictionary  break out of this loop.
						cout << z << " " << dictionary[z] << endl;//prints iterations,space,the word in the dictionary if it exists
						break;// add 1 time
					}
				}

			}
			//this tells if its in the dictionary. if its not it prints a 0 for each new word found.
			cout << found << endl;

			for (i = 0; i != 100; i++)
			{
				if (found==false)
					//add it to the dictionary[i] in an empty string in the index  1.
			}

			temp = "";//clears temp  string or resests string temp because for loops it  goes top to bottom and starts back up from top to bottom.
		}				//at nothing and loops over always reseting it.
		
	}


	cout << temp << endl;

	system("pause");
	return 0;
}
Topic archived. No new replies allowed.