Create a simple command-line tool that takes a text file as input and outputs the number of words in the file.
-
Input:
- The tool should take a text file as a command-line argument.
-
Processing:
- Count the number of words in the file. Consider a word as any sequence of characters separated by whitespace.
-
Output:
- Display the total number of words in the file.
# Using the tool in different languages
# Example in Python
python word_count.py input.txt
# Example in JavaScript (Node.js)
node word_count.js input.txt
# Example in Ruby
ruby word_count.rb input.txt
# Example in Go
go run word_count.go input.txt
# Example in C++
./word_count_cpp input.txt
- Keep the tool simple, focusing on the core functionality of counting words.
- Consider handling errors, such as when the file does not exist or when there are issues reading the file.
- Write the tool in multiple languages to compare and contrast the implementations.
This project allows you to explore file I/O, command-line argument handling, string manipulation, and basic program structure in different programming languages. It's a great way to gain familiarity with the syntax and features of various languages while working on a practical task.