11 Replies - 3992 Views - Last Post: 25 January 2009 - 10:02 PM Rate Topic: -----

#1 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

error LNK2019: unresolved external symbol

Posted 23 January 2009 - 08:54 PM

Ok I'm working on my program compile it gives me a few error... cool. I fix those errors by going to the line number VS 05 points out are problems. Finally I get all my errors sorted out and I compile it... but this time I get two new errors. This next part is verbatim from my build log so I'll put it up for youse to look through.

Quote

Creating temporary file "c:\Documents and Settings\Brandon\My Documents\Visual Studio 2005\Projects\BMatykunas 10-48\BMatykunas 10-48\Debug\RSP00002523483860.rsp" with contents
[
/OUT:"C:\Documents and Settings\Brandon\My Documents\Visual Studio 2005\Projects\BMatykunas 10-48\Debug\BMatykunas 10-48.exe" /INCREMENTAL /MANIFEST /MANIFESTFILE:"Debug\BMatykunas 10-48.exe.intermediate.manifest" /DEBUG /PDB:"c:\Documents and Settings\Brandon\My Documents\Visual Studio 2005\Projects\BMatykunas 10-48\debug\BMatykunas 10-48.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

".\Debug\main.obj"

".\Debug\BMatykunas 10-48.exe.embed.manifest.res"
]
Creating command line "link.exe @"c:\Documents and Settings\Brandon\My Documents\Visual Studio 2005\Projects\BMatykunas 10-48\BMatykunas 10-48\Debug\RSP00002523483860.rsp" /NOLOGO /ERRORREPORT:PROMPT"
Output Window

Linking...
main.obj : error LNK2019: unresolved external symbol "void __cdecl datainTable(int * *,struct _iobuf *)" (?datainTable@@YAXPAPAHPAU_iobuf@@@Z) referenced in function _main
C:\Documents and Settings\Brandon\My Documents\Visual Studio 2005\Projects\BMatykunas 10-48\Debug\BMatykunas 10-48.exe : fatal error LNK1120: 1 unresolved externals
Results

Build log was saved at "file://c:\Documents and Settings\Brandon\My Documents\Visual Studio 2005\Projects\BMatykunas 10-48\BMatykunas 10-48\Debug\BuildLog.htm"
BMatykunas 10-48 - 2 error(s), 0 warning(s)


Now here's my code:

/*Welcome to Project 10-48
	Author: Brandon Matykunas
	Date:   1/22/09
*/

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <conio.h>

#define FLUSH while (getchar( ) != '\n')

void datainTable (int** dataset, FILE* dataIn);
void requestInfo (int** dataset);

int** builder (FILE* dataIn);
int findMin (int* forRow);
int findMax (int* forRow);
int little (int firstNum, int secNum);
int big (int firstNum, int secNum);

float calcAve (int* forRow);

int main (void)
{
	FILE* dataIn;
	
	int** dataset;
	
	printf("Please wait while I access import.txt...\n");
	
	if(!(dataIn = fopen("C:\\import.txt", "r")))
	{
		printf("\aError! import.txt is missing. This program will now close.\n");
		return 101;
	}
	else
	{
		dataset = builder(dataIn);
		datainTable(dataset, dataIn);
		requestInfo(dataset);
	}
	fclose (dataIn);

	return 0;
}

void datainTable (FILE* dataIn, int** dataset)
{
	int row = 0, col;

	while (dataset[row] != NULL)
	{
		for(col = 1; col <= *dataset[row]; col++)
			fscanf_s(dataIn, "%d", dataset[row] + col);
			row++;
	}
	return;
}

void requestInfo (int** dataset)
{
	int row = 0, rowSmall, rowBig;
	double averageRow;

	while (dataset[row] != NULL)
	{
		rowSmall = findMin (dataset[row]);
		rowBig = findMax (dataset[row]);
		averageRow = calcAve (dataset[row]);

		printf("Ok, for row %d, we have:\n", row + 1);
		printf("A minimumn of: %d\n", rowSmall);
		printf("A maximum of: %d\n", rowBig);
		printf("And finally a row average of: %f\n\n", averageRow);
		row++;
	}
	return;
}

int** builder (FILE* dataIn)
{
	int row = 0, col = 0;
	int** dataset;
	int rows;

	while(fscanf_s(dataIn, "%d %d", &row, &col) != '\n');

	dataset = (int**) calloc (row + 1, sizeof(int*));

	for (rows = 0; rows < row; rows++)
	{
		dataset[rows] = (int*) calloc (col + 1, sizeof(int));
		dataset[rows] [0] = col;
	}
	dataset[rows] = NULL;

	return dataset;
}

int findMin (int* forRow)
{
	int rowSmall = INT_MAX, col;

	for (col = 1; col <= *forRow; col++)
		rowSmall = little (rowSmall, *(forRow + col));
	return rowSmall;
}

int findMax (int* forRow)
{
	int rowBig = INT_MIN, col;

	for (col = 1; col <= *forRow; col++)
		rowBig = big (rowBig, *(forRow + col));
	return rowBig;
}

float calcAve (int* forRow)
{
	float sum = 0, averageRow;
	int col;

	for (col = 1; col <= *forRow; col++)
		sum += (float)*(forRow + col);
	averageRow = sum / *forRow;
	return averageRow;
}

int little (int firstNum, int secNum)
{
	return (firstNum < secNum ? firstNum : secNum);
}

int big (int firstNum, int secNum)
{
	return (firstNum > secNum ? firstNum : secNum);
}



At first I thought that I had forgotten a header file, but I can't think of any other header files that I would need. If you guys can't point out my problem I'd appreciate it. Thanks.

This post has been edited by Jayman: 24 January 2009 - 10:05 AM


Is This A Good Question/Topic? 0
  • +

Replies To: error LNK2019: unresolved external symbol

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3105
  • View blog
  • Posts: 19,144
  • Joined: 14-September 07

Re: error LNK2019: unresolved external symbol

Posted 23 January 2009 - 09:11 PM

Look at your prototype:

void datainTable (int** dataset, FILE* dataIn);




Now now look at how you defined the function later:

void datainTable (FILE* dataIn, int** dataset)




You reversed the parameters. change one of them and you should be good to go :).
Was This Post Helpful? 0
  • +
  • -

#3 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

Re: error LNK2019: unresolved external symbol

Posted 23 January 2009 - 09:25 PM

duh, thanks That got it to compile. New problem though:

My program gets to
Please wait while I access import.txt...

This is the first printf statement in my main function, but in any case my program hangs here and does nothing. I imagine this has something to do with how my file is read into my array, but I really don't know.

Can you tell me if I'm headed in the right direction, and if so, how do I fix this?

Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: error LNK2019: unresolved external symbol

Posted 24 January 2009 - 05:42 AM

Infinite loop:
while(fscanf_s(dataIn, "%d %d", &row, &col) != '\n');


fscanf_s returns an integer which is the number of fields converted (never going to be more than 2) or EOF on error. I also don't think you want to have that semicolon following it...you likely want:
while(fscanf_s(dataIn, "%d %d", &row, &col) != '\n')
{
    // process data in row and col
}

Was This Post Helpful? 1
  • +
  • -

#5 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

Re: error LNK2019: unresolved external symbol

Posted 24 January 2009 - 07:02 AM

Ok here's what I had before:

while(fscanf_s(dataIn, "%d %d", &row, &col) != '\n');
	
		dataset = (int**) calloc (row + 1, sizeof(int*));



and here's what I have now:

while(fscanf_s(dataIn, "%d %d", &row, &col) != '\n')
	{
		dataset = (int**) calloc (row + 1, sizeof(int*));
	}



This still hangs, is there more that I should include in the brackets? Say the for statement for example?

Thanks

Scratch that last idea I just tried this:

while(fscanf_s(dataIn, "%d %d", &row, &col) != '\n')
	{
		dataset = (int**) calloc (row + 1, sizeof(int*));
	

		for (rows = 0; rows < row; rows++)
		{
			dataset[rows] = (int*) calloc (col + 1, sizeof(int));
			dataset[rows] [0] = col;
		}
		dataset[rows] = NULL;
	}



and it still hangs.... So now I have no idea.
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: error LNK2019: unresolved external symbol

Posted 24 January 2009 - 09:11 AM

You're not "listening"! This statement:
while(fscanf_s(dataIn, "%d %d", &row, &col) != '\n')

is always going to be true! The result of fscanf_s will always be, in this case, 0, 1, 2, or -1 on error; it's never going to be equal to the ASCII value of '\n', so it's going to continuously execute.

What exactly are you trying to accomplish in builder, and what is the format of the file you're trying to read?
Was This Post Helpful? 0
  • +
  • -

#7 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: error LNK2019: unresolved external symbol

Posted 24 January 2009 - 10:05 AM

Modified title to be more descriptive of the problem.
Was This Post Helpful? 0
  • +
  • -

#8 buckrogers1965  Icon User is offline

  • New Member

Reputation: 9
  • View blog
  • Posts: 87
  • Joined: 23-January 09

Re: error LNK2019: unresolved external symbol

Posted 24 January 2009 - 02:26 PM

I wrote a formated input tutorial a few years ago with some example code.

http://tldp.org/LDP/...e32/rogers.html

The different between my loop and yours is that mine says:

while (fscanf (stream, "%e%s", &value, label) != EOF)

and yours says:

while(fscanf_s(dataIn, "%d %d", &row, &col) != '\n')

See the '\n' and EOF?

fscanf returns an EOF on a read error, or the number of items that were converted, zero or more. So the only way that fscanf would ever be equal to '\n' is if it returned 10 items.

This post has been edited by buckrogers1965: 24 January 2009 - 02:27 PM

Was This Post Helpful? 1
  • +
  • -

#9 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

Re: error LNK2019: unresolved external symbol

Posted 24 January 2009 - 06:06 PM

@ JackOfAllTrades: the file I'm trying to scan into my array is a .txt file

In general:

I changed the '\n' to EOF and what's good is that the program doesn't hang anymore, what's bad is that it has developed a new problem in that it prints a statement for 475 rows, and calculates the max, min, and average for all of them and what's even worse is that every single value is 0.

I am attaching the import.txt file to this so that you can look it over and see a little bit more of what I'm trying to do.

Thanks again for your help
Was This Post Helpful? 0
  • +
  • -

#10 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

Re: error LNK2019: unresolved external symbol

Posted 24 January 2009 - 11:33 PM

Does anyone know anything about scanning a txt file into an array? I actually don't think I have this right. I've heard of sprintf which is used to scan files into strings. Would this apply here, and if so, how would I implement it?

Thanks
Was This Post Helpful? 0
  • +
  • -

#11 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: error LNK2019: unresolved external symbol

Posted 25 January 2009 - 07:04 AM

OK, so the first line has the row and column count. That's what I suspected. You mean sscanf, rather than sprintf, and you could do that as well.

Here is a full program that will read a file of your format into a 2-d array and print it out. This should help a little:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define DATA_FILE "import.txt"

int main(void)
{
	int rowCount = 0, colCount = 0;
	int i = 0;
	int **data = NULL;
	FILE *fp = fopen(DATA_FILE, "r");
	if (!fp)
		return 1;

	/* Read column and row count first */
	if (fscanf(fp, "%d %d", &rowCount, &colCount) != 2)
	{
		fclose(fp);
		return 1;
	}

	/* Allocate memory for rows */
	data = calloc(rowCount, sizeof(**data));
	if (!data)
	{
		fclose(fp);
		return 1;
	}

	for (; i < rowCount; ++i)
	{
		int j = 0;
		/* Allocate memory for this row's columns */
		data[i] = calloc(colCount, sizeof(*data));
		if (!data[i])
		{
			/* Cleanup; reuse j variable */
			for (; j < i; ++j)
				free(data[i]);
			free(data);
			fclose(fp);
			return 1;
		}

		for (; j < colCount; ++j)
		{
			/* Read value into column */
			if (fscanf(fp, "%d", &data[i][j]) != 1)
			{
				/* Failure...cleanup and exit*/
				for (j = 0; j <= i; ++j)
					free(data[i]);
				free (data);
				fclose(fp);
				return 1;
			}
		}
	}

	/* Close the file */
	fclose(fp);

	for (i = 0; i < rowCount; ++i)
	{
		int j = 0;
		for (; j < colCount; ++j)
		{
			printf("[%d:%d] %d\n", i, j, data[i][j]);
		}
		/* Free memory for this row's columns */
		free(data[i]);
	}

	/* Free memory for rows */
	free (data);
	return 0;
}

Was This Post Helpful? 0
  • +
  • -

#12 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

Re: error LNK2019: unresolved external symbol

Posted 25 January 2009 - 10:02 PM

Ok, thank you to everybody that helped. I finally figured out what was going wrong, and how to fix it.

The problem ended up being with the while statement, and what I had realized is that I was trying to tell my program was that it need to allocate memory to the array while my row & col was not equal to 2. Problem was that it was equal to two, so it just built the memory heap and filled it with NULL values which explains the zero's in MAX MIN and AVERAGE. I would imagine the 475 rows that it created can be explained by how large the memory heap was.

So to fix this I changed the:

while(fscanf_s(dataIn, "%d %d", &row, &col) != 2)

//into this

if(fscanf_s(dataIn, "%d %d", &row, &col) != 2)
     //Kill program statement
else
{
    //Ran the rest of the program
}




Everything else worked just fine. So again thanks for your help. This has certainly been a learning experience for me.

Here is my entire source in case anyone wants to look it over to make improvements
/*Welcome to Project 10-48
	Author: Brandon Matykunas
	Date:   1/22/09
*/

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <conio.h>

#define FLUSH while (getchar( ) != '\n')
#define DATA_FILE "C:\\import.txt"

void datainTable (int** dataset, FILE* dataIn);
void requestInfo (int** dataset);

int** builder (FILE* dataIn);
int findMin (int* forRow);
int findMax (int* forRow);
int little (int firstNum, int secNum);
int big (int firstNum, int secNum);

float calcAve (int* forRow);

int main (void)
{
	
	int** dataset;
	
	printf("Please wait while I access import.txt...\n\n");
	
	FILE* dataIn = fopen(DATA_FILE, "r");
	if(!dataIn)
		return 0;
	else
	{
		dataset = builder(dataIn);
		datainTable(dataset, dataIn);
		requestInfo(dataset);
	}
	fclose (dataIn);

	return 0;
}

void datainTable (int** dataset, FILE* dataIn)
{
	int row = 0, col;

	while (dataset[row] != NULL)
	{
		for(col = 1; col <= *dataset[row]; col++)
			fscanf_s(dataIn, "%d", dataset[row] + col);
			row++;
	}
	return;
}

void requestInfo (int** dataset)
{
	int row = 0, rowSmall, rowBig;
	double averageRow;

	while (dataset[row] != NULL)
	{
		rowSmall = findMin (dataset[row]);
		rowBig = findMax (dataset[row]);
		averageRow = calcAve (dataset[row]);

		printf("Ok, for row %d, we have:\n", row + 1);
		printf("A minimumn of: %d\n", rowSmall);
		printf("A maximum of: %d\n", rowBig);
		printf("And finally a row average of: %f\n\n", averageRow);
		row++;
	}
	_getch();
	return;
}

int** builder (FILE* dataIn)
{
	int row = 0, col = 0;
	int** dataset;
	int rows;

	if(fscanf_s(dataIn, "%d %d", &row, &col) != 2)
		return 0;
	else
	{
		dataset = (int**) calloc (row + 1, sizeof(int*));
	

		for (rows = 0; rows < row; rows++)
		{
			dataset[rows] = (int*) calloc (col + 1, sizeof(int));
			dataset[rows] [0] = col;
		}
		dataset[rows] = NULL;
	}

	return dataset;
}

int findMin (int* forRow)
{
	int rowSmall = INT_MAX, col;

	for (col = 1; col <= *forRow; col++)
		rowSmall = little (rowSmall, *(forRow + col));
	return rowSmall;
}

int findMax (int* forRow)
{
	int rowBig = INT_MIN, col;

	for (col = 1; col <= *forRow; col++)
		rowBig = big (rowBig, *(forRow + col));
	return rowBig;
}

float calcAve (int* forRow)
{
	float sum = 0, averageRow;
	int col;

	for (col = 1; col <= *forRow; col++)
		sum += (float)*(forRow + col);
	averageRow = sum / *forRow;
	return averageRow;
}

int little (int firstNum, int secNum)
{
	return (firstNum < secNum ? firstNum : secNum);
}

int big (int firstNum, int secNum)
{
	return (firstNum > secNum ? firstNum : secNum);
}


This post has been edited by webmin: 25 January 2009 - 10:04 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1