Using Linked Lists as Histograms

April 26, 2010 at 09:37:15
Specs: Windows XP
I am trying to write a program that counts the total number of words and the number of distinct words in a text file. I am writing the program in basic C programming. I want to use a linked list as a histogram, where each node contains a string representing a distinct word, and an integer counter indicating the number of times it appears in the file. Heres an example of what I have.

struct wNode {
char word[WSIZE]; /* word being counted */
int wc; /* count of this word */
struct wNode *next; /* ptr to next node */

I wrote a function to strip each word of any punctuation, and change it to lowercase so it doesnt count the strings "Today", "today", and "today." as different words. Heres the function.

/* strip: converts str w to lowercase and strips punctuation */
char *strip(char *w)
char *s, *p; /* ptrs to beginning of string to strip */

for (p = s = w; *w != '\0'; w++) {
if (!(ispunct(*w)))
*s++ = tolower(*w);
*s = '\0';
return p;

This is as far as I could get on my own if someone could help me out id really appreciate it. Thanks.

See More: Using Linked Lists as Histograms

Report •

April 26, 2010 at 10:07:59
Ignoring the issue of "its" and "it's" being counted as the same word, what do you have, besides a struct and a function? Do you have a high-level list of steps?

Report •
Related Solutions

Ask Question