Linked Lists

Upon compiling my code I am getting the error:
List.cxx: In function 'void build_list(std::ifstream&, char*)':
List.cxx:72: error no matching function for call to 'concordance::insert(char*&, int&)'
concordance.h:25: note: candidates are: void concordance::insert(char (&)[9], int&)

Header File:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46


#ifndef CONCORDANCE_H
#define	CONCORDANCE_H

#include <iostream>
#include <cstdlib>

const int MAX = 8;

class concordance
{
	public:
	    //typedef
	    typedef char Word[MAX+1];	

	    //constructor
	    concordance();

	    //destructor
	    ~concordance();

	    //modification member functions
	    void insert(Word& word, int& count);
	    void remove(Word& word);
	    int get_count(Word& word);

	    //constant member functions
	    int length() const;

	    //friend member functions
	    friend std::ostream& operator << (std::ostream& out_s, concordance& c); 

	private:
	    struct Node
	    {
    		Word wd;
    		int count;
    		Node *next;
	    };
	    Node *first;	

	    Node* get_node(Word& word, int& count, Node* link);   
};

#endif 


Class Definition File:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

//class definition
#include "concordance.h"
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;

concordance::concordance()
{
	first = NULL;
}

concordance::~concordance()
{
	Node *temp;
	while(first != NULL)
	{
	    temp = first;
	    first = first -> next;
	    delete temp;
	}
}

void concordance::insert(Word& word, int& count)
{
	Node *prev;

	if(first == NULL || strcmp(first -> wd, word) > 0)
	    first = get_node(word, count, first);
	else
	{
	    prev = first;

	    while(prev -> next != NULL && strcmp(prev -> next -> wd, word) > 0)
	    	prev = prev -> next;
	    prev -> next = get_node(word, count, prev -> next);
	}
}

void concordance::remove(Word& word)
{
	Node *prev, *temp;
	prev = temp;
	if(prev -> wd == word)
	{
	    first = first -> next;
	    delete prev;
	}
	else
	{
	    while(strcmp(prev -> next -> wd, word) > 0)
		prev = prev -> next;
	    temp = prev -> next;
	    prev -> next = temp -> next;
	    delete temp;
	}
}

int concordance::get_count(Word& word)
{
	while(strcmp(first -> wd, word) != 0)
	    first = first -> next;
	
	return first -> count;
}
		
int concordance::length() const
{
    Node *cursor;
    int len;

    len = 0;
    for(cursor = first; cursor != NULL; cursor = cursor -> next )
      len++;
    return len;
}

concordance::Node* concordance::get_node (Word& word, int& count, Node* link)
{
    Node *temp;

    temp = new Node;
    strcpy(temp-> wd, word);
    temp-> next = link;
    temp -> count = count+1;
    return temp;
}

ostream& operator << (ostream& out_s, concordance& c)
{
    concordance::Node *cursor;

    out_s << "Word" << setw(10) << " " << "Count" << endl;
    out_s << "--------------------" << endl;

    for(cursor = c.first; cursor != NULL && cursor->next != NULL; cursor = cursor-> next )
      out_s << cursor-> wd << setw(10) << " " << cursor -> count << endl;

    if(cursor != NULL)
      out_s << cursor-> wd << setw(10) << " " << cursor -> count << endl;
    out_s << "--------------------" << endl;

//    out_s << "The file contains " << c.length << " distinct words. ";

    return out_s;
}


Client Program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cctype>
#include "concordance.h"
using namespace std;

void read_word(ifstream& in_file, char array[]);
void build_list(ifstream& in_file, char array[]);

int main()
{
	char file_name[100];
	ifstream in_file;
	char array[MAX+1];

	cout << "Enter a file name: "; cin >> file_name;
	
	in_file.open(file_name);

	build_list(in_file, array);

	in_file.close();

	return EXIT_SUCCESS;
}

void read_word(ifstream& in_file, char array[])
{
	char ch;
	int i = 0;

	in_file.get(ch);

	while(isalpha(ch) && !isspace(ch))
	{ 
	    	if(i > MAX-1)
		{
		    while(!isspace(ch))
			in_file.get(ch);
			break;
		}
		
		ch = tolower(ch);
		array[i] = ch;
		i++;
		in_file.get(ch);
	}

	for(int j = 0; j < i; j++)
		cout << array[j];
		cout << endl;

}
	
void build_list(ifstream& in_file, char array[])
{
	concordance c;
	int count = 0;

	while(!in_file.eof())
	{
	    read_word(in_file, array);
	    c.insert(array, count);
	}

	cout << c;
}


I have been, and currently am, working on this but have been unsuccessful thus far. I have had similar errors when working with this program previously but resolved those without much issues, this one however seems to have me stuck.
Last edited on
The insert function takes a reference to an array of 9 char but you try to pass it a char pointer. If you change build_list to
void build_list(ifstream& in_file, char (&array)[MAX+1]) I think it should work. Why not use the Word typedef everywhere?
The typedef Word is just a type created for the struct not the whole program. Also, I'm unable to compile using the syntax you mentioned. My compiler says it expects an initializer before the ' )'
I tried using the typedef everywhere and it works now, thank you for the suggestion.
Topic archived. No new replies allowed.