Objective
Write a C program that takes a filename and a word as command-line arguments. The program will read the file and count the occurrences of the specified word.
Requirements
- Create a function that counts the occurrences of the specified word in each line
- Take two command-line arguments: the name of the file and the word to count, if both are not specified it should give a usage message.
- Open the file
- Read each line in the file in a loop using
fgets
- Call the occurrence counter function
- Add the number of occurrences to a running total
- Output the results using "The word '%s' occurs %d times in the file\n"
Example Usage
./word_count filename.txt crazy
The word 'crazy' occurrs 18 times in the file
Steps to Complete
- Implement the requirements
- Compile and test the program
- Run /challenge/tester
- Get flag
Connect with SSH
Link your
SSH key, then connect with:
ssh hacker@pwn.college