Fast Grep
Description
Discuss (8 comments)
The goal of this puzzle is to find the first line that contains a given word and to print its number on the standard output.
If no line is found that contains the given word, the value 0 should be printed. The match should be case-sensitive (the word must match the same case as the input-argument's case).
For example, let this be myfile.txt:
Calling your program with the following arguments:
If no line is found that contains the given word, the value 0 should be printed. The match should be case-sensitive (the word must match the same case as the input-argument's case).
Input Specifications
Your program must take 2 arguments:- the word to look for
- the input file in which to search for the word
For example, let this be myfile.txt:
Hello World
Output Specifications
The output result should printed on the standard output. The result to be printed is the number of the line where the keyword was first found, or 0 if the keyword cannot be found.Calling your program with the following arguments:
your_program_name Hello myfile.txtMust produce the following output:
1
© CoderCharts - All Rights Reserved
| Type | Puzzle | Pass | 848 | Fail | 623 | ||
| Scoring | Language | Level | Easy | Points | 100 | ||
| Tags | file reading | ||||||
Unit Tests
| Name | CPU Unit | Memory Unit |
|---|---|---|
Simple testTesting the rest of the example |
||
Big file, test #1A word near the beginning |
||
Big file, test #2A word near the end |
||
Big file, test #3A missing word due to case |
||
Big file, test #4A missing word |
Confirm that you want to switch languages
Your current edits will be lost.
Confirm that you wish to load a previous submission
Your current edits will be lost.