-
struct probelm
i am a beginner, i am doing a program that user can input the filename, and i can run in to count the word frequency using link list.
i have 5 list operation, like create, add, search, print, and delete.
BUT the main problem i faced is when doing the struct, i don't know how to define the structure? if i using char* in word, then i don't know how to get the string(word) into the link list when i using char* to define now....
anybody can help me. really don't know how to do
struct Node {
int count;
char* word;
struct Node* next;
struct Node* theList;
};
-
First thing, put your code in code tags....
Second, What do you mean by frequency?
If you mean the count of number of words, what's the problem, you can use built in string function strlen(your_String) to find the length of the string.....
I am not sure, what are you asking about....
Be more specific so that i could think over...
Regards...
-
Code:
struct Node {
int count;
char* word;
struct Node* next;
struct Node* theList;
};
I have no idea how it is going to work. Is this your assignment? If not, don't create your own linked list (unless you want to try to implement it for educational purposes). Use std::list as linked list and std::wstring instead of char*. Instead of creating whole structure you could just write:
Code:
std::list<std::wstring> Words;
-
if you want to count the words just see how many whitespace have letters after them like this
Code:
//put the file into a string
int wordcount = 0;
for(int i = 0; i < strlen(string); i++)
if(string[i] == ' ' && string[i+1] != ' ')
wordcount++;