# A Makefile for Program 0, CS480
all: testalphabet testspecial
OTHER_ALPHA__OBJS = testalphabetcount.o alphabetcount.o
OTHER_SPECIAL__OBJS = testspecialcharcount.o specialcharcount.o
CC = gcc
CFLAGS = -g -std=c99
testalphabet: ${OTHER_ALPHA__OBJS}
${CC} -o testalphabet ${OTHER_ALPHA__OBJS}
testspecial: ${OTHER_SPECIAL__OBJS}
${CC} -o testspecial ${OTHER_SPECIAL__OBJS}
${OTHER_SPECIAL__OBJS} ${OTHER_SPECIAL__OBJS}:count.h
clean:
rm -f *.o testalphabet testspecial
/* charcount.h - This header file include type definitions (including function prototypes) and macros
used for the programing assignment zero.
*/
#include <stdio.h>
#define ALPHABETSIZE 26 //The total number of alphabetical letter from a - z (case insensitive)
#define SPECIALCHARSIZE 5 // The number of these special characters ',' '.' ';' ':' '!'
void alphabetlettercount(char *path, char *filetowrite, long alphabetfreq[]);
/**
The alphabetlettercount function counts the frequency of each alphabet letter (a-z, case insensitive) in all the .txt files under
directory of the given path and write the results to a file named as filetowrite.
Input:
path - a pointer to a char string [a character array] specifying the path of the directory; and
filetowrite - a pointer to a char string [a character array] specifying the file where results should be written in.
alphabetfreq - a pointer to a long array storing the frequency of each alphabet letter from a - z:
alphabetfreq[0]: the frequency of 'a'
alphabetfreq[1]: the frequency of 'b'
... ...
alphabetfreq[25]:the frequency of 'z'
Output: a new file named as filetowrite with the frequency of each alphabet letter written in
*/
void specialcharcount(char *path, char *filetowrite, long charfreq[]);
/**
The specialcharcount function counts the frequency of the following 5 special characters:
',' '.' ':' ';' '!'
in all the .txt files under directory of the given path and write the results to a file named as filetowrite.
Input:
path - a pointer to a char string [a character array] specifying the path of the directory; and
filetowrite - a pointer to a char string [a character array] specifying the file where results should be written in.
alphabetfreq - a pointer to a long array storing the frequency of the above 5 special characters
charfreq[0]: the frequency of ','
charfreq[1]: the frequency of '.'
charfreq[2]: the frequency of ':'
charfreq[3]: the frequency of ';'
charfreq[4]: the frequency of '!'
Output: a new file named as filetowrite with the frequency of the above special characters written in
Steps recommended to finish the function:
1) Find all the files ending with .txt and store in filelist.
2) Read all files in the filelist one by one and count the frequency of each alphabet letter only (a - z). The array
long alphabetfreq[] always has the up-to-date frequencies of alphabet letters counted so far. If the letter is upper case, convert
it to lower case first.
3) Write the result in the output file: filetowrite in following format:
character -> frequency
example:
, -> 20
. -> 11
: -> 20
; -> 11
! -> 12
Assumption:
1) You can assume there is no sub-directory under the given path so you don't have to search the files
recursively.
2) Only .txt files are counted and other types of files should be ignored.
*/
/*
* alphabetcount.c - this file implements the alphabetlettercount function.
*/
#include <stdio.h>
#include "count.h"
/**
The alphabetlettercount function counts the frequency of each alphabet letter (a-z, case insensitive) in all the .txt files under
directory of the given path and write the results to a file named as filetowrite.
Input:
path - a pointer to a char string [a character array] specifying the path of the directory; and
filetowrite - a pointer to a char string [a character array] specifying the file where results should be written in.
alphabetfreq - a pointer to a long array storing the frequency of each alphabet letter from a - z:
alphabetfreq[0]: the frequency of 'a'
alphabetfreq[1]: the frequency of 'b'
... ...
alphabetfreq[25]:the frequency of 'z'
Output: a new file named as filetowrite with the frequency of each alphabet letter written in
Steps recommended to finish the function:
1) Find all the files ending with .txt and store in filelist.
2) Read all files in the filelist one by one and count the frequency of each alphabet letter only (a - z). The array
long alphabetfreq[] always has the up-to-date frequencies of alphabet letters counted so far. If the letter is upper case, convert
it to lower case first.
3) Write the result in the output file: filetowrite in following format:
letter -> frequency
example:
a -> 200
b -> 101
... ...
Assumption:
1) You can assume there is no sub-directory under the given path so you don't have to search the files
recursively.
2) Only .txt files are counted and other types of files should be ignored.
*/
void alphabetlettercount(char *path, char *filetowrite, long alphabetfreq[])
{
// TO-DO: please fill your code here ...
}
/*
* specialcharcount.c - this file implements the specialcharcount function.
*/