Keep getting following error and I do not know what is cause it:
1 2 3
1>ProgrammingAssignment3.obj : error LNK2005: "struct node_2 * beginning" (?beginning@@3PAUnode_2@@A) already defined in Autocomplete.obj
1>Term.obj : error LNK2005: "struct node * start" (?start@@3PAUnode@@A) already defined in ProgrammingAssignment3.obj
1>C:\Users\Tnorth2620\Documents\Computer Projects and Classes\College\CS 216\ProgrammingAssignment3\Debug\ProgrammingAssignment3.exe : fatal error LNK1169: one or more multiply defined symbols found
#include "Term.h"
#include "Autocomplete.h"
int main()
{
Term txt_file;
string file;
int num;
string file_name;
ifstream infile;
int size = 0;
int largest_pos = 0;
string prefix;
int results = 0;
Autocomplete sort;
int position = 0;
//call function to create list
txt_file.CreateList(file);
sort.CreateList_2(file);
//ask user for file to open and store in variable
cout << "What file would you like to open: ";
getline(cin, file_name);
infile.open(file_name);
//check if file name is valid
if(infile.fail())
{
//if not display error message and end program
cout <<"The file cannot be opened, terminating program!" << endl;
system("pause");
exit(0);
}
//use loop to read through file
while(infile >> num && (getline(infile, file)))
{
//call function to insert each line in file into linked list one following the other
txt_file.InsertAtEnd(num,file, size);
//increase size
size += 1;
//increase largest_pos
largest_pos += 1;
}
txt_file.sort_query();
infile.clear();
infile.seekg(infile.beg);
cout <<"Please enter query and number of results to return: ";
cin >> prefix;
cin >> results;
while(infile >> num && (getline(infile, file)))
{
sort.search(file, prefix, num, results, position);
//increase size
size += 1;
//increase largest_pos
largest_pos += 1;
}
sort.sort_weight();
sort.print_2();
//txt_file.sort_weight();
//txt_file.print(file);
cout << endl << endl << endl;
//call function to print current file to screen
//txt_file.print(file_name);
system("pause");
return 0;
}
#include "Term.h"
void Term :: CreateList(string file)
{
//delclare node temp.
node *temp;
//initialize temp
temp = new(node);
//set text(which was declared in class) to file.
temp -> text = file;
temp -> next = NULL;
//If start of list equals NULL enter statement.
if (start == NULL)
{
temp -> prev = NULL;
//set beginning of list to temp.
start = temp;
}
//if not enter else statement.
else
{
//enter loop if the term after start is not NULL.
while (start -> next != NULL)
{
//set start equal to line proceeding it.
start = start -> next;
//set that line equal to temp.
start -> next = temp;
//set previous line equal to start.
temp -> prev = start;
}
}
//End function and return too main.
}
//Creat function that insert something at end of file taking parameters file(content of file), and size(number of lines).
//This function will enter lines into list but reorder them since orginally it insert backwards and finally it will insert new line.
void Term :: InsertAtEnd(int num, string file, int size)
{
//Declare nodes temp and temp_2.
node *temp, *temp_2;
//set temp_2 to beginning of list(start).
temp_2 = start;
//if you have not reached the end of the file enter loop and do not exit till you reach end of file.
for (int i = 0; i < size; i++)
{
//progress through loop.
temp_2 = temp_2 -> next;
}
//initialize temp.
temp = new(node);
temp -> text = file;
temp -> number = num;
//if line following q equals NULL enter
if (temp_2 -> next == NULL)
{
//progress q and set equal to tmp.
temp_2 -> next = temp;
//set line following tmp to NULL.
temp -> next = NULL;
//set line Proceeding tmp to temp_2.
temp -> prev = temp_2;
}
//if not enter if statement
else
{
//set line following tmp equal to line following temp_2.
temp -> next = temp_2 -> next;
temp -> next -> prev = temp;
temp_2 -> next = temp;
temp -> prev = temp_2;
}
}
void Term :: sort_query ()
{
node * temphead = start;
//ListNode * tempnode = NULL;
string temp;
int temp_2;
int counter = 0;
while (temphead)
{
temphead = temphead->next;
counter++;
}
temphead = start -> next;
for (int j=0; j<counter; j++)
{
while (temphead->next) //iterate through list until next is null
{
if (temphead->text > temphead->next->text)
{
/*tempnode = temphead;
temphead = temphead->next;
temphead->next = tempnode;*/
temp = temphead->text;
temphead->text = temphead->next->text;
temphead->next->text = temp;
temp_2 = temphead->number;
temphead->number = temphead->next->number;
temphead->next->number = temp_2;
temphead = temphead->next;//increment node
}
else
temphead = temphead->next;//increment node
}
temphead = start;//reset temphead
}
}
//Declare void function(does not return anything) that will print the current linked list to the screen when requested
//or output it to the input file when requested. It takes parameters letter(letter entered when prompted in main function) and file_name
//(name of file).
void Term :: print()
{
//declare and initialize line_number.
int line_number = 1;
//declare node temp_2
node *temp_2;
//set equal to start or beginning of list
temp_2 = start;
//if first line is equal to blank space enter statement
if( temp_2->text == "")
{
//proceed to followinf line skipping over this plan line
temp_2 = temp_2-> next;
}
//enter loop if temp_2 != null (have not reached end of file)
while (temp_2 != NULL && temp_2-> text != "")
{
//output line number and each line in the list till you reach the end
cout << temp_2 -> number << " " << temp_2 -> text << endl;
//progress to next line
temp_2 = temp_2 -> next;
//increment line number
line_number += 1;
}
}
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <list>
usingnamespace std;
#ifndef TERM_H
#define TERM_H
//declare node structure
struct node
{
//declare string text
string text;
//string name;
int number;
//declare next and prev node
struct node *next;
struct node *prev;
}*start; //start or head of linked list
//delcare class LinkedList
class Term
{
//public part
public:
//declare all fucntions
//this will create linked list
void CreateList(string file);
//insert a line at end of list
void InsertAtEnd(int num,string file, int size);
void print();
//void sort_weight ();
void sort_query();
friendclass Autocomplete;
//void SelectionSort();
//void swap(node *p1, node*p2);
//private
private:
//declare head and tail
node *head;
node *tail;
};
#endif