• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

I keep getting a fatal error while trying to load a file.

I keep getting some errors while trying to load my file into a structure and I don't understand what they are for or where I'm making the mistake. These are the erros I'm getting also. Any help would be greatly appreciated :)

1>------ Build started: Project: practice, Configuration: Debug Win32 ------
1>warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(234) : see declaration of 'fopen'
1>practice.obj : error LNK2019: unresolved external symbol "void __cdecl loadFile(struct _iobuf *,struct myRecords *,char * const)" (?loadFile@@YAXPAU_iobuf@@PAUmyRecords@@QAD@Z) referenced in function _main
1>C:\Users\Theresa\Desktop\practice\Debug\practice.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

#include <iostream>
#include <stdlib.h>
#include <cstdio>
#include <stdio.h>

struct customers
	int cust_id;
	char cust_name[19];
	char state[3];
	char discount;
	double balance_due;
	int order_out;

struct myRecords
	customers rec[10];

using namespace std;

//functions go here
void loadFile(FILE *, struct myRecords *, char[]);

int main()
{	char buffer[50];
	int counter = 0;

	myRecords table, *point_table;
	point_table = &table;

	FILE *fp;
	fp = fopen("ASSIGNV1.DAT", "r");
	if (fp == NULL)
		printf ("Error opening file! ");
		loadFile(fp, point_table, buffer);


void loadFile(FILE *fp, struct myRecords table, char buffer[])
	int counter = 0;
		fgets(buffer, 20, fp);
		table.rec[counter].cust_id = atoi(buffer);
		fgets(table.rec[counter].cust_name, 20, fp);
		fgets(table.rec[counter].state, 20, fp);
		fgets(buffer, 20, fp);
		table.rec[counter].discount = buffer[0];
		fgets(buffer, 20, fp);
		table.rec[counter].balance_due = atof(buffer);
		fgets(buffer, 20, fp);
		table.rec[counter].order_out = atoi(buffer);

Open in new window

1 Solution
Hi reesee324,

IMO the problem is the declaration and implementation of 'loadFile' are different.

First you declare it with second paramter is of type 'struct myRecords*', but in the implementation you declare the second parameter to be of type 'struct myRecords'. Therefor the linker doesn't find the function needed.

You have to change the 'struct myRecords table' to i.e. 'struct myRecords* table' and modify the kind how this param is accessed in the function.

Hope that helps,

reesee324Author Commented:
Okay thanks! Sometimes you just need a new set of eyes :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now