Implementing concordance with a linked list

/closed
Last edited on
You forgot to define function wrd_list which takes a reference to ifstream and ponter to char.

Instead you have defined function which takes a reference to ifstream and reference to char array.
I changed

1
2

void wrd_list(ifstream& file_in, char (&word_list) [MAX + 1])

to:
 
void wrd_list(ifstream& file_in, Word word_list)

which I think fixes the problem. But I got another problem:

main.cpp|47|error: no matching function for call to 'List::ins(char*&, int&)'|
ins takes a reference to character array, and you are passing pointer to it.
You need to pass array by reference to achieve anything. And this is not easy to get right as you noticed. Arrays are weak, they will decay to pointer at slightest wrong move. So try to not use array references in your code (and array pointers). Wrap everything in class or use standard ones.
Sorry im still learning the concept of pointers and how they are used. I dont see where that the argument Word word_list is a pointer. What can I do to only pass it by reference. Thanks so much for your help btw I really appreciate it
Word word_list is equal to char word_list[MAX+1] which is by rule of array-pointer decay is char* word_list

On the other hand ins takes a Word&, in other words char (&)[MAX+1], it will not take a pointer, nor array of any other size. You need to match your types (either allow to use a pointer in ins or change wrd_list to take reference too)

C arrays and pointers are counter-intuitive and hard to get right.
I changed the wrd_list function to void wrd_list(ifstream& file_in, Word &word_list)

It got another error because of it. When i call that function in the main it doesn't like the second argument wrd_list(file_in, arr); How do I pass this correctly?
Last edited on
Change every place where you pass a character array to accept Word&
my functions in main look like:

void wrd_list(ifstream& file_in, Word &word_list)

void read_input(ifstream& file_in, Word &arr)

In the header file:

Node* get_node (Word& entry, int& freq, Node* link);

void remove ( const Word& target);

int get_count(Word& word);


I get the error:
main.cpp|29|undefined reference to `wrd_list(std::basic_ifstream<char, std::char_traits<char> >&, char*)'|
Did you fix function prototypes as well?
I just fixed those. It compiles now but after I enter the name of the text file, it runs an infinite loop of just what appears to be whitespace.
Try to determine where it happens. Add some debug output to your functions to see your program progress. (Or just use a debugger)
It appears that the file is not being opened. I added a line of text after the while loop that checks for !eof and its just looping that text.
It is opening the file. I made a function to check that and i just did a test that printed the text from the file. It did all that fine.

EDIT: I got a step closer. I added the line file_in.get(chr); to the read_input function right before the while loop. It displays everything in the text file besides the last word.
Last edited on
Topic archived. No new replies allowed.