CS5JA Guest Lecture, Wednesday 03/05/2008
Phill Conrad, substituting for Diana Franklin
Today's topics: reinforce command line args, and reading from a file
- Writing a program to count all the words in a text file
- Plan: try something easier first
- first write a program to count all the lines in a file
- then modify it to count all the words in a file
- Input: name of a file
- we'll take it from the command line
- Output:
- number of lines (or words) in the file
We will proceed in a number of phases, showing how the program evolves at each step.
Along the way, we might review a bit about "scope" too: where a variable is defined.
- Remember: braces { } are like Vegas:
- What happens in Vegas, stays in Vegas
- For the most part: what happens inside a set of braces, stays inside that set of braces
- This is not a hard and fast rule, but a general guideline...
Program Code:
Note that this code was put online before class, so it may not reflect any changes made during the lecture.
Finished Products:
In-between versions (some of which have syntax errors, or logic errors)