A few things I noticed:
1. I don't think getting the file line by line is the best way to go here. The way you have it, you're going to keep spitting out lines you read from the file. Then when you find a line that has a word enclosed in brackets, you're asking the user to put in that entire line. Instead, why not grab the text one word at a time? Like this:
while ( !libfile.eof() ){ string sCurrentWord; libfile >> sCurrentWord; // do other stuff}
When you use the ">>" operator on a string like that, the ifstream will automatically look for spaces and line breaks so that you just get a single word. I think that would be useful in your case.
2. There's really no need for you to use arrays at all here. In fact, the way you're using them is basically just guaranteeing a
buffer overflow in certain cases. Think about it: your array of strings has space for 100 lines. What happens if your text file has 101 lines? Since you're not checking for this case, you'll write to the non-existent 101th array index and end up corrupting some memory. Instead, I suggest using the string's "+" operator to perform string concatenation. See when you do this:
string string1 = "I ";string string2 = "Rule!";string1 += string2;cout << string1;
You'd get the output "I Rule!" on the console. This means that as you're pulling strings out of your input file, you can simply keep adding the new string to a single string containing all of the text you've read so far. You can also do this as much as you want and you don't have to worry about running out of space like you do with an array, since string will keep increasing the size of its internal array as needed. If you really want to use arrays, I would suggest looking up the std::vector class which behaves like an array but will resize itself as you add new elements.
3. As Evil Steve said, sizeof( sUserline
) does not give you the length of a string. sizeof returns the amount of bytes in memory a type uses, and for complex reasons this is unrelated to how long the actual string of characters is. Instead, just use the length() method the string class to find out how long it is. Like this:
for (int i = 0; i < sUserline.length(); ++i)