Spell check using pthreads in C

Hi

I have a school project where we suppose to make a spell check using pthreads,
it is suppose to have customer.h using linked list, will have 3 member functions (misspelled list, task list, word count)

and will have Server.h, this one can point to the linked list of customer.h,
but it will store a dictionary(.csv file) about 16_millions.csv of words.

the task list will be populated with the list of words to be checked .And then under main.cpp, it will take in a word from task list (also about millions), it will take the strings one by one, it will check if the string is in the dictionary, if it is, it goes to the next one without doing anything with that one found in the dictionary.csv(server.h), if the word is misspelled, it saves it in the misspelled list. basically it will be comparing two lists.

please help!!

it does this until all the words are read in.
Hi there,

Welcome to the forums. As per the rules on the forum, we don't just give people solutions to homework assignments.

You mention that you need a customer.h and server.h file, with specified functions and linked list.
Please make an attempt at writing those and come back to us with the code and any specific problems you are having.

If you need help getting started, just let us know and we'll take it step by step.

All the best,
NwN
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//this is my Server.h
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <ctime>
#include <string>
#include "Customer.h"


using namespace std;

/*template <class Type>		
struct nodeType
{
    Type info;
    nodeType<Type>*link;
};

template <class Type>
struct nodeTypeCount
{
    Type info;
    long counter;
    nodeType<Type>*link;
};*/

template <class Type>
class Server
{
public:
    Server();
    void fill_Dictionary();
    //int length const();
    void fill_SpellingCheck();
private:
    int sizeof_DicList;
    nodeType<Type>*DictionaryList_first;
    nodeType<Type>*DictionaryList_last;
    nodeType<Type>*DictionaryList_newNode;
};

template <class Type>
Server<Type>::Server()
{
    DictionaryList_first = NULL;
    DictionaryList_last = NULL;
    sizeof_DicList = NULL;
}

template <class Type>
void Server<Type>::fill_Dictionary()
{
    nodeType<Type>*DictionaryList_first;
    nodeType<Type>*DictionaryList_last;
    nodeType<Type>*DictionaryList_newNode;
    //Randomising Which File Is to be used to populate 'TaskList'.
    //If choose == 0, populate with 'Dictionary1.csv'
    //If choose == 1, populate with 'Dictionary2.csv'
    int b;
    string words_1;
    srand (time(NULL));
    b = rand()%2;

    if (b == 0)
    {
        ifstream infile("Dictionary1.txt");
        while (!infile.eof())
        {
            infile >> words_1;//read words from a file and store a them in words
            DictionaryList_newNode = new nodeType<Type>; //allocate memory of type nodeType
            //and store the address of the
            //allocated memory in newNode
            DictionaryList_newNode->info = words_1;  //copy 'words' into the
            //info field of newNode
            DictionaryList_newNode->link = NULL;   //initialize the link field of
            //newNode to NULL
            if (DictionaryList_first == NULL) //if first is NULL, the list is empty;
                //make first and last point to newNode
            {
                DictionaryList_first = DictionaryList_newNode;
                DictionaryList_last = DictionaryList_newNode;
                sizeof_DicList = NULL;
            }

            else //list is not empty
            {
                DictionaryList_last->link = DictionaryList_newNode; //insert newNode at the end of the list
                DictionaryList_last = DictionaryList_newNode; //set last so that it points to the
                //actual last node in the list
                sizeof_DicList++;
            }
        }//end of while loop
        infile.close();//TaskList is filled
    }

    if(b == 1)
    {
        ifstream infile("Dictionary2.csv");
        while(!infile.eof())
        {
            infile >> words_1;//read words from a file and store a them in words
            DictionaryList_newNode = new nodeType<Type>; //allocate memory of type nodeType
            //and store the address of the
            //allocated memory in newNode_1
            DictionaryList_newNode->info = words_1;  //copy 'words' into the
            //info field of newNode
            DictionaryList_newNode->link = NULL;   //initialize the link field of
            //newNode to NULL
            if (DictionaryList_first == NULL) //if first is NULL, the list is empty;
                //make first and last point to newNode
            {
                DictionaryList_first = DictionaryList_newNode;
                DictionaryList_last = DictionaryList_newNode;
                sizeof_DicList = NULL;
            }
            else //list is not empty
            {
                DictionaryList_last->link = DictionaryList_newNode; //insert newNode at the end of the list
                DictionaryList_last = DictionaryList_newNode; //set last so that it points to the
                //actual last node in the list
                sizeof_DicList++;
            }
            cout << sizeof_DicList << endl;
        }//end of while
        infile.close();
    }//end of if statement
}

Last edited on
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//This is my Customer.h
#ifndef CUSTOMER_H
#define CUSTOMER_H

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <ctime>
#include <string>
#include "Server.h"

using namespace std;

template <class Type>
struct nodeType
{
    Type info;
    nodeType<Type>*link;
};

template <class Type>
struct nodeTypeCount
{
    Type info;
    long counter;
    nodeTypeCount<Type>*link;
};

template <class Type>
class Customer
{
public:
    Customer();
    void fill_TaskList();
    void fill_MisspelledList();
    int size() const;
    void fill_WordCountList();
protected:
private:
    string words;
    int counter;
    // Pointers for linked list 'TaskList'
    nodeType<Type>*TaskList_first;// Pointer to the first node
    nodeType<Type>*TaskList_last;// Pointer to the last node
    nodeType<Type>*TaskList_newNode;// Pointer to the newNode node
    nodeType<Type>*TaskList_current;

    // Pointers for linked list 'MisspelledList'
    nodeTypeCount<Type>*MisspelledList_first;
    nodeTypeCount<Type>*MisspelledList_last;
    nodeTypeCount<Type>*MisspelledList_newNode;

    // Pointers for linked list 'WordCountList'
    nodeTypeCount<Type>*WordCountList_first;
    nodeTypeCount<Type>*WordCountList_last;
    nodeTypeCount<Type>*WordCountList_newNode;
};

template <class Type>
Customer<Type>::Customer()
{
    TaskList_first = NULL;
    TaskList_last = NULL;
    counter = NULL;
    fill_TaskList();
    TaskList_current=TaskList_first;

    while(TaskList_current->link!=NULL)
    {
        cout<< TaskList_current->info <<endl;
        TaskList_current = TaskList_current->link;
    }
}

template <class Type>
void Customer<Type>::fill_TaskList()
{
    //Randomising Which File Is to be used to populate 'TaskList'.
    //If choose == 0, populate with '1.csv'
    //If choose == 1, populate with '2.csv'
    int a;
    string words;
    srand (time(NULL));
    //a = rand()%2+1;
    a=0;
    //if (first != NULL) // if the list is non-empty, make it empty
    //destroyList();

    if (a == 0)
    {
        ifstream infile("1.txt");
        while (infile >> words)
        {
            //infile >> words;//read words from a file and store a them in words
            TaskList_newNode = new nodeType<Type>; //allocate memory of type nodeType
            //and store the address of the
            //allocated memory in newNode
            TaskList_newNode->info = words;  //copy 'words' into the

            //info field of newNode
            TaskList_newNode->link = NULL;   //initialize the link field of
            //newNode to NULL
            if (TaskList_first == NULL) //if first is NULL, the list is empty;
                //make first and last point to newNode
            {   ;
                TaskList_first = TaskList_newNode;
                TaskList_last = TaskList_newNode;
            }

            else //list is not empty
            {
                TaskList_last->link = TaskList_newNode; //insert newNode at the end of the list
                TaskList_last = TaskList_newNode; //set last so that it points to the
                //actual last node in the list
            }
        }//end of while loop
        infile.close();//TaskList is filled
    }

    if(a == 1)
    {
        ifstream infile("2.txt");
        while(!infile.eof())
        {
            infile >> words;//read words from a file and store a them in words
            TaskList_newNode = new nodeType<Type>; //allocate memory of type nodeType
            //and store the address of the
            //allocated memory in newNode
            TaskList_newNode->info = words;  //copy 'words' into the
            //info field of newNode
            TaskList_newNode->link = NULL;   //initialize the link field of
            //newNode to NULL

            if (TaskList_first == NULL) //if first is NULL, the list is empty;
                //make first and last point to newNode
            {
                TaskList_first = TaskList_newNode;
                TaskList_last = TaskList_newNode;
            }

            else //list is not empty
            {
                TaskList_last->link = TaskList_newNode; //insert newNode at the end of the list
                TaskList_last = TaskList_newNode; //set last so that it points to the
                //actual last node in the list
            }
        }//end of while

        TaskList_last->link=NULL;
        infile.close();
    }//end of if statement
}



#endif // CUSTOMER_H 
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//This is my main
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <ctime>
#include <string>
#include "Customer.h"
#include "Server.h"

using namespace std;

int main()
{
    Customer<string> *Customer;
    return 0;
}[code]
Last edited on
The following are errors I get on C:
fortune@ubuntu:~/Desktop/coms$ make
g++ -pthread -O3 -lrt -g -c main.cpp -o main.o
In file included from Customer.h:10:0,
                 from main.cpp:7:
Server.h:37:5: error: ‘nodeType’ does not name a type
Server.h:38:5: error: ‘nodeType’ does not name a type
Server.h:39:5: error: ‘nodeType’ does not name a type
Server.h: In constructor ‘Server<Type>::Server()’:
Server.h:45:5: error: ‘DictionaryList_first’ was not declared in this scope
Server.h:46:5: error: ‘DictionaryList_last’ was not declared in this scope
Server.h: In member function ‘void Server<Type>::fill_Dictionary()’:
Server.h:53:5: error: ‘nodeType’ was not declared in this scope
Server.h:53:18: error: expected primary-expression before ‘>’ token
Server.h:53:20: error: ‘DictionaryList_first’ was not declared in this scope
Server.h:54:18: error: expected primary-expression before ‘>’ token
Server.h:54:20: error: ‘DictionaryList_last’ was not declared in this scope
Server.h:55:18: error: expected primary-expression before ‘>’ token
Server.h:55:20: error: ‘DictionaryList_newNode’ was not declared in this scope
Server.h:70:42: error: expected type-specifier before ‘nodeType’
Server.h:70:42: error: expected ‘;’ before ‘nodeType’
Server.h:102:42: error: expected type-specifier before ‘nodeType’
Server.h:102:42: error: expected ‘;’ before ‘nodeType’
In file included from main.cpp:8:0:
Server.h: At global scope:
Server.h:28:7: error: redefinition of ‘class Server<Type>’
Server.h:28:7: error: previous definition of ‘class Server<Type>’
Server.h:43:1: error: redefinition of ‘Server<Type>::Server()’
Server.h:43:1: error: ‘Server<Type>::Server()’ previously declared here
Server.h:51:6: error: redefinition of ‘void Server<Type>::fill_Dictionary()’
Server.h:51:6: error: ‘void Server<Type>::fill_Dictionary()’ previously declared here
make: *** [main.o] Error 1
fortune@ubuntu:~/Desktop/coms$ D^C
fortune@ubuntu:~/Desktop/coms$ 

Last edited on
Hi

If you could go back and edit your posts to use code tags it'll be easier for people to understand your code. Esp. as there's quite a bit of it.

Thanks

Andy

How to use code tags
http://www.cplusplus.com/articles/jEywvCM9/
Hi there,

I think the following will fix quite a few of those errors:

error: ‘nodeType’ does not name a type


Server.h has the nodeType struct commented out, so the compiler doesn't know it.


error: redefinition of ‘class Server<Type>’

Your Server.h has no include guards (#ifndef / #define / #endif), so if you include it in both main.cpp and customer.h, it gets included twice, hence "redefined".

Could you change those and try again please?

All the best,
NwN
Topic archived. No new replies allowed.