Create an application which can be used to search for a string in files.
Input: The application will receive two command line parameters. The first parameter is a path to a file or folder, while the second parameter is the string to be searched for (maximum length of 128 characters).
Output: Print the output to stdout lines in format “<file>(<position>): <prefix>…<suffix>”.
<file>: Name of a file containing the string
<position>: Offset within the file where the string started (zero based).
<prefix>: Contains three characters in front of the match
<suffix>: Contains three characters after the match.
When there are not enough characters for the whole prefix or suffix (at the beginning or end of the file), use as many as there are available. In the prefixes and suffixes, tabs should be printed as “\t” and new lines as “\n”.
Assume that the path can point to either a single text file, or to a directory with files and/or more folders (your application must be able to recursively traverse and process all files in sub-directories). The application must take into account that files might be very large (potential memory constraints/limitations). The application must not crash for any reason (ensure that exceptions are handled properly, handling of errors from API functions, etc), and should print meaningful errors messages when a problem occurs (informing when there was not enough arguments provided, input path is invalid, etc).
Note! The solution should make use of multi-threading in processing data (at least theoretically). Please note that a single threaded solution may be faster in this sequential scan, especially on slower drives. Try to maximize speed and compare your results with a single threaded solution.
What will we evaluate
How you build your solution is up to you. Please take your time when building your solution. It is always better to take longer and provide a great solution, than take less time and provide an “ok” solution. We will use your solution to estimate your software engineering experience level. A well done solution will guarantee an interview, higher job level, and a more appealing salary offer. Your solution will be discussed in details during an interview.
Your source code should demonstrate:
- your programming style,
- usage of object oriented programming principles,
- C++ programming best practices,
- systematic use of naming conventions,
- usage of the right comments at the right place,
- good code structure,
- handling of error states and exceptions,
- avoidance of dangerous or error prone constructs,
- your understanding of “inner workings” of C++ and standard functions (e.g.: wastage of memory or unnecessary (implicit/internal) string/memory copy operations).
Avoid memory leaks of course (e.g. due to unhandled exception). We prefer to see C++ 14 standard libraries used, but usage of Boost is also acceptable.
A quote that explains it quite well: “Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” :-)
Please send your source code to: email@example.com