files directory by typing
cp -rd ~mc38/labs/word-count/files /wordcount
wc filename
The program wc outputs four fields, namely
wordcount.cc write three procedures
countChars(char*), countWords(char*) countLines(char*) that takes the
filename of a file as the parameter and returns repsectively the
number of chars,the number of words and the number of lines.
wc
Unix commands, i.e., wordcount will take command line
arguments and process the file(s) and prints the number of
characters, words and lines in that file in that order. For the
command line argument to work, it will not be enough to start with
int main() instead it will have to have arguments in the
main function.
for (int i = 0; i < argc; i++){
...
...
}
wordcount story1.txt story2.txt story3.txt story4.txtand if you did not change the original
story files a correct output will be
3853 650 74 story1.txt 4500 774 102 story2.txt 6825 1159 139 story3.txt 9561 1657 191 story4.txt
numOfChars, numOfWords and
numOfLines. Write a procedure count(int&, int&,
int&, string fileName) that takes the fileName,
reads the file only once and returns the required character, word and
line counts as reference parameters. You may need to convert a string
to a stream using istringstream.
Wildcards on Unix : Do you know that your successful program
also accepts the wildcards "*" and "?" (for
instance, instead of listing story1.txt to
story4.txt, we can issue the command
wordcount story?.txt
or
wordcount story*