Skip to content
This repository was archived by the owner on Sep 4, 2022. It is now read-only.

DamianDhesi/WordFrequency

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

By Damian Dhesi

Programmed from scratch for a project in my C class.

This is program is designed to take in one or more files as input and return a sorted list of 
the most frequent words. Words are sorted in descending order of frequency and in reverse 
alphabetical order if there is a tie in frequency. The program can take an optional argument of 
-n <num> to specify how many words to output. If the -n argument is not given then the top 10 
most frequent words will be printed out by default. 

A hashtable implementation was used to store the words as they were read. This allows the 
frequency of each word to be increased fairly quickly if it appears again in the input.
The hashtable uses seperate chaining to resolve collisions. In addition, the hashtable will 
double it's size in order to maitain fast look up so that it does not devolve into simply
being a glorified linked list. 

The Makefile will complie the program utilizing the command "make fw" or "make all". 
"make clean" can be used to remove all object files

Usage: fw [-n num] [ file1 [ file 2 ...] ]

Sample Runs (In Ubuntu):

$ ./fw war_and_peace.txt
The top 10 words (out of 22938) are:
    34825 the
    22686 and
    16871 to
    15096 of
    10663 a
    10081 he
     9364 in
     8187 that
     8097 his
     7367 was
$ ./fw
input via standard input
The top 10 words (out of 4) are:
        2 input
        1 via
        1 standard
$ ./fw DoesNotExist
DoesNotExist: No such file or directory
The top 10 words (out of 0) are:
$ ./fw -n ARealNumber
usage: fw [-n num] [ file1 [ file 2 ...] ]
$ ./fw FakeFile main.c
FakeFile: No such file or directory
The top 10 words (out of 208) are:
       36 the
       32 to
       32 if
       25 file
       23 word
       21 n
       20 i
       16 is
       14 a
       12 words
$ chmod u-r test
$ ./fw test
test: Permission denied
The top 10 words (out of 0) are:
$ ./fw -n 2 war_and_peace.txt
The top 2 words (out of 22938) are:
    34825 the
    22686 and
$

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published