error LNK2019

error LNK2019: unresolved external symbol

Page 1 of 1

8 Replies - 4456 Views - Last Post: 31 March 2007 - 11:35 PM Rate Topic: -----

#1 mdneilson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-March 07

error LNK2019

Posted 29 March 2007 - 06:45 PM

#include <iostream>
#include <cstdlib>
using namespace std;

bool check(char **line1, char **line2, int size);
void sort1(char **line1, char size);
void sort2(char **line2, char size);
void swap(char*& c1, char*& c2);	

int main()
{
	char **line1 = new char *[];
	char **line2 = new char *[];
	int i = 0;
	
	cout << "Input a sentence." << endl;
	for (char x = ' '; x >= ' '; i++)
	{
		cin.get(x);
		*line1[i] = x;
	}
	cout << "\n\nInput another sentence." << endl;
	for (char x = ' '; x >= ' '; i++)
	{
		cin.get(x);
		*line2[i] = x;
	}

	sort1(line1, i);
	sort2(line2, i);
	check(line1, line2, i);
	system("PAUSE");

 return 0;   
}

bool check(char **line1, char **line2, int size)
{  
	int i = 0;
	if(size > 0)
	{
		if(line1[i] == line2[i])
			return true;

		else
			cout << "Not an anagram." << endl;
			return false;

		check(line1, line2, size-1);
	}
	return true;
}

void sort1(char **line1, int size)
{
  int j, k;

  for (k=1; k < size; ++k)
  {
	j = k;							  
	while (j > 0 && *line1[j] < *line1[j-1])  
	{								   
	  swap(line1[j], line1[j-1]);		   
	  --j;							  
	}
  }
}

void sort2(char **line2, int size)
{
  int j, k;

  for (k=1; k < size; ++k)
  {
	j = k;							  
	while (j > 0 && *line2[j] > *line2[j-1])  
	{								   
	  swap(line2[j], line2[j-1]);		   
	  --j;							  
	}
  }
}

void swap(char*& c1, char*& c2)	
{
  char *temp;						

  temp = c1;
  c1 = c2;
  c2 = temp;
}



If you are wondering: this program just checks if the inputs are anagrams.

Returns the errors:

Hw1.obj : error LNK2019: unresolved external symbol "void __cdecl sort2(char * *,char)" (?sort2@@YAXPAPADD@Z) referenced in function _main
Hw1.obj : error LNK2019: unresolved external symbol "void __cdecl sort1(char * *,char)" (?sort1@@YAXPAPADD@Z) referenced in function _main
C:\Users\Milo Brandybuck\Programs\Lab10\Debug\Lab10.exe : fatal error LNK1120: 2 unresolved externals

How do I fix this?
Thank in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: error LNK2019

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: error LNK2019

Posted 29 March 2007 - 06:55 PM

Are those the only errors? I'm a little surprised it gets past the declarations of line1 and line 2.
Was This Post Helpful? 0
  • +
  • -

#3 Xing  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 19
  • View blog
  • Posts: 725
  • Joined: 22-July 06

Re: error LNK2019

Posted 29 March 2007 - 10:02 PM

@mdneilson

You will require loop to allocate memory for pointer to pointer and you have to specify size in new.

This post has been edited by Xing: 29 March 2007 - 10:03 PM

Was This Post Helpful? 0
  • +
  • -

#4 mdneilson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-March 07

Re: error LNK2019

Posted 30 March 2007 - 08:15 PM

View PostXing, on 29 Mar, 2007 - 10:02 PM, said:

@mdneilson

You will require loop to allocate memory for pointer to pointer and you have to specify size in new.


The memory allocation is fine -- it is a dynamic array, clearly, so the size is determined at runtime, hence not setting the size. I have used this kind of declaration in other programs with no problems.

The error appears when linking. It seems to be an error with the function calls, but I can't figure out if that is right, or how to solve it if it is. :blink:

(if there is something I have to do to the array initialization to make it link correctly, or if there is some heap concept that I may not be grasping, please correct me. -- i am still pretty new to C++)

This post has been edited by mdneilson: 30 March 2007 - 08:19 PM

Was This Post Helpful? 0
  • +
  • -

#5 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: error LNK2019

Posted 31 March 2007 - 11:30 AM

the prototype for sort1() and sort2() are (second parameter a char)
void sort1(char **line1, char size);
void sort2(char **line2, char size);



but the definitions are (second parameter an int )
void sort1(char **line1, int size)

void sort2(char **line2, int size)


change the prototype to match the definition?

also you have
int main()
{
	char **line1 = new char *[];
	char **line2 = new char *[];


without the array sizes specified - GNU C++ thows this out
what compiler are you using that allows this? I suggest that you specify a size?

This post has been edited by horace: 31 March 2007 - 11:33 AM

Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: error LNK2019

Posted 31 March 2007 - 11:39 AM

To adhere to standards, to dynamically declare a 2d array will require the use of an allocation loop as Xing mentioned...I'd also be interested to know what compiler allows that type of declaration.
Was This Post Helpful? 0
  • +
  • -

#7 mdneilson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-March 07

Re: error LNK2019

Posted 31 March 2007 - 12:04 PM

I am using VS2005.

...after changing the 'char' to 'int' the program runs, but breaks on the heap (not surprising after your suggestions).

--Sorry to seem rude, I wasn't trying to be, I was just trying to say that I've had this type of declaration work before and I didn't see why it wouldn't work again.

edit: looking back I only used one array like this, not 2.

This post has been edited by mdneilson: 31 March 2007 - 12:49 PM

Was This Post Helpful? 0
  • +
  • -

#8 mdneilson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-March 07

Re: error LNK2019

Posted 31 March 2007 - 12:51 PM

Amadeus --- I like your 1337 page from your signature. I AGREE!
Was This Post Helpful? 0
  • +
  • -

#9 mdneilson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-March 07

Re: error LNK2019

Posted 31 March 2007 - 11:35 PM

After some thinking i have changed my code a bit. Maybe it was easier to allocate the memory, but I honestly don't know how. :blush:

#include <iostream>
#include <cstdlib>
using namespace std;

bool check(char **line[2], int size);
void sort(char **line[2], int size);
void swap(char*& c1, char*& c2);	

int main()
{
	int i = 0, r = 0, c = 2;
	char **line = new char *[c];

	for(int i = 0; i < c; i++)
		line[i] = new char[r];
	
	cout << "Input a sentence." << endl;
	for (char x = ' '; x >= ' '; i++)
	{
		cin.get(x);
		line[0][i] = x;
	}
	cout << "\nInput another sentence." << endl;
	for (char x = ' '; x >= ' '; i++)
	{
		cin.get(x);
		line[1][i] = x;
	}

	sort(line, i);
	check(line, i);

	int z = i;
	for (int y; y < z; y++)
	cout << *&line[0][i] << "   " << *&line[1][i] << endl;

	if (true)
		cout << "\nIs an anagram\n." << endl;
	else
		cout << "\nIs not an anagram\n." << endl;

	system("PAUSE");
	return 0;  
}

bool check(char **line[2], int size)
{  
	int i = 0;
	if(size > 0)
	{
		if(line[0][i] == line[1][i])
			return true;
		else
		{
			return false;
			size = 0;
		}
		check(line, size-1);
	}
}

void sort(char **line[2], int size)
{
  int j, k, l;
  for (k=1; k < size; ++k)
  {
	j = k;
	for (l = 0; l < 2; l++)
	{
		while (j > 0 && line[l][j] < line[l][j-1])  
		{								  
		swap(line[l][j], line[l][j-1]);		  
		--j;
		}
	}
  }
}

void swap(char*& c1, char*& c2)	
{
  char *temp;
  temp = c1;
  c1 = c2;
  c2 = temp;
}



i am getting errors at:
	sort(line, i);
		check(line, i);


error C2664: 'sort' : cannot convert parameter 1 from 'char **' to 'char **[]'
error C2664: 'check' : cannot convert parameter 1 from 'char **' to 'char **[]'

I can't seem to get around getting errors at these lines.

edit:When moving everything into the main, i get memory access violations... damn being new to this. please help with any suggestions.

*tears out hair*

This post has been edited by mdneilson: 01 April 2007 - 02:20 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1