Hey guys. I put together some code that finds a word in a string (string x called strx) and returns a substring around that word (string y called range1). I am now running another for loop on string y to find a second word. The word is in string y, but the for loop isn't executed and "no match was found here" is returned. (I'm accessing one hashTable called "happy" in string x and one called "unhappy" in string y. The word "angry" is in string y and in hashTable "unhappy" and should be found.) Hopefully this is a minor syntax issue:
It was just part of the explanation. "string x" refers to the variable strx. "string y" refers to the variable range1.
I am running it in the console. Everything works except the nested for loop. I nested working loops and now the nested one is not called ever. Your link is the tutorial I used already.
Regardless of checking one character at a time, why isn't the inner for loop run?
The above should be treated like a main.cpp file without its imports. The hash table is not relevant to why the inner for loop is not called. I can't post the actual program. This is an example of a syntax issue.
There are no preconditions. It simply brings in a word from a list in the hash table to search 'strx' for and then makes a range around it called range1, then searches range1.
There is some syntactic reason the inner for loop won't search range1 created around the word "giggling".
range1 is (-4 words, giggling, +4 words).
range1 is searched for the word "angry" (this should happen and doesn't)
This prints out in the console:
./a.out
how much angry? No giggling up a storm allowed
no match was found
My point is I am running it on my end using the hashTable file. I need someone to read the code and point out what is stopping the loop. I'll look into why the hash table wouldn't be getting imported, but nothing is set up differently than the working version. Do you see anything wrong with the code provided it isn't an issue accessing the hash table?
You then single step the code to the next instruction.
If you wind up at line 50-something, then you need to examine how you set up your hashTable.
If you get to line 22, then step again and then examine the 'check' variable to see if it contains a string you expect. You might be reading the file OK, but the result can still be a hash table full of garbage.
You can figure out a lot from just using the debugger to step through the code and look what happens. Whenever you have those "I didn't expect..." moments, then there's a good change you found a bug.
> Do you see anything wrong with the code provided it isn't an issue accessing the hash table?
No.
You're a 100% right. I extracted the code for testing and it caused hash table connection errors. I wrote everything into the program that I reviewed and it compiled the first time. I got a vector error when running it that I'll be wrapping my head around, but with debugging we found which loop it is. Thanks for the guidance.