i'm trying to read a file into an array struct using a function, i get the errors:

1.error LNK2019: unresolved external symbol "void __cdecl loadarray(struct ElementType * const,int)" (?loadarray@@YAXQAUElementType@@H@Z) referenced in function _main

2.fatal error LNK1120: 1 unresolved externals

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

ifstream fin;

int i =0;

struct ElementType
{
string Name;
int atomicnumber;
double atomicmass;
double density;
}r1,r2,r3;

void loadarray(ElementType A[],int nItems);

const int maxsize = 15;

ElementType E[15];

int main()
{
fin.open("element.dat");

loadarray(E,1);

return 0;
}

void loadarray(ElementType A[],int& nItems)
{
	while(!fin)
	{
	
	fin>>A[i].Name;
	fin>>A[i].atomicmass;
	fin>>A[i].atomicnumber;
	fin>>A[i].density;
	i++;

	}
}

Recommended Answers

All 6 Replies

Code tags:

[code]

// put code here

[/code]

Please edit your post and put the code tags in. It's easier to read.

i'm trying to read a file into an array struct using a function, i get the errors:

1.error LNK2019: unresolved external symbol "void __cdecl loadarray(struct ElementType * const,int)" (?loadarray@@YAXQAUElementType@@H@Z) referenced in function _main

2.fatal error LNK1120: 1 unresolved externals

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

ifstream fin;

int i =0;

struct ElementType
{
string Name;
int atomicnumber;
double atomicmass;
double density;
}r1,r2,r3;

void loadarray(ElementType A[],int nItems);

const int maxsize = 15;

ElementType E[15];

int main()
{
fin.open("element.dat");

loadarray(E,1);

return 0;
}

void loadarray(ElementType A[],int& nItems)
{
while(!fin)
{

fin>>A[i].Name;
fin>>A[i].atomicmass;
fin>>A[i].atomicnumber;
fin>>A[i].density;
i++;

}
}

Close on the tags:

[code]
// code here
[/code]

The closing tag needs to have a slash. You still have time to edit your last post. Stick it in there and the code will show with line numbers, syntax highlighting, etc.

Thanks.

Prototype and Function definition parameters donot match. Change the function definitions second argument to a pass by value and not pass by reference. And i think it will have no problem compiling

And Yeah, the next time you post code.. please make sure that you use the code tags properly. Proper code tags lead to faster and better answers :)

thanks it works now !!!!!

-- wrong, oops ---

And please format your code. It's very hard to follow.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.