It would be easy to make everything in the file lowercase and find it, but I want to find the string with the original capitalization so I could put it to a pointer and print it later. For example FIND_WORD ransom. File Word found. Line added DISPLAY rAnSoM nOtE. yOu HaVe TiLl nOon.
Asked
Active
Viewed 116 times
0
-
And your question is? – David Schwartz Nov 10 '14 at 03:36
-
@DavidSchwartz The question is in the title. – Neil Kirk Nov 10 '14 at 03:37
-
@NeilKirk Oh. Okay. Then the answer is trivial -- see my answer. – David Schwartz Nov 10 '14 at 03:40
1 Answers
1
Go through the file line by line. For each line, go through the string from beginning to end.
For each starting point in the line, do a case-insensitive compare of the subsequent characters in the string to the characters in the word you're trying to find. If they all match, output that entire line as originally read.
In other words, don't convert anything to lower case. Instead, do a case-insensitive compare.

David Schwartz
- 179,497
- 17
- 214
- 278
-
What does code for a case-insensitive compare look like? if('B'=='b')? – Terry Light Nov 10 '14 at 04:10
-
It can be `if (std::tolower(x) == std::tolower(y))` or look at [these answers](http://stackoverflow.com/questions/11635/case-insensitive-string-comparison-in-c). – David Schwartz Nov 12 '14 at 10:17