F
Foodbank
Hi,
I have to write a program that will use linked lists to print the
number of unique words, total words, and the most frequent word from a
text file. I've gotten a decent amount of it done except for the
linked lists. I did not paste my code that tells the machine what a
word is, it works fine and it'll be easier to read that way without it.
Below is the code:
//****code from here to next section is good, I don't need help
there****//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct list_elem {
char *word;
int count;
struct list_elem *next;
};
struct list_elem *head; /* the head pointer is initially NULL */
int get_word(char *);
void add_to_list(char *);
void list_walk(void);
int unique_words, total_words;
struct list_elem *most_frequent_elem;
main() {
char word_buff[100];
while(get_word(word_buff))
add_to_list(word_buff);
list_walk();
printf("there are %d unique words out of %d total words\n",
unique_words, total_words);
printf("the most frequent word is <%s> which used %d times\n",
most_frequent_elem->word, most_frequent_elem->count);
}
//**************************
//***********help here and below
void add_to_list(char *word_buff) {
/* *CODE TO SEARCH THE LIST AND COUNT REPEAT WORDS
/* ** CODE TO MAKE NEW ELEMENTS FOR BRAND NEW WORDS
void list_walk() {
/* ****** CODE TO WALK THE LIST AND GATHER THE STATS
}
Any help is greatly appreciated.
Thanks,
James
I have to write a program that will use linked lists to print the
number of unique words, total words, and the most frequent word from a
text file. I've gotten a decent amount of it done except for the
linked lists. I did not paste my code that tells the machine what a
word is, it works fine and it'll be easier to read that way without it.
Below is the code:
//****code from here to next section is good, I don't need help
there****//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct list_elem {
char *word;
int count;
struct list_elem *next;
};
struct list_elem *head; /* the head pointer is initially NULL */
int get_word(char *);
void add_to_list(char *);
void list_walk(void);
int unique_words, total_words;
struct list_elem *most_frequent_elem;
main() {
char word_buff[100];
while(get_word(word_buff))
add_to_list(word_buff);
list_walk();
printf("there are %d unique words out of %d total words\n",
unique_words, total_words);
printf("the most frequent word is <%s> which used %d times\n",
most_frequent_elem->word, most_frequent_elem->count);
}
//**************************
//***********help here and below
void add_to_list(char *word_buff) {
/* *CODE TO SEARCH THE LIST AND COUNT REPEAT WORDS
/* ** CODE TO MAKE NEW ELEMENTS FOR BRAND NEW WORDS
void list_walk() {
/* ****** CODE TO WALK THE LIST AND GATHER THE STATS
}
Any help is greatly appreciated.
Thanks,
James