Solved

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

Posted on 2011-03-16
2
396 Views
Last Modified: 2012-05-11
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! ");
	}
	else
	{
		loadFile(fp, point_table, buffer);
	}
		

}


void loadFile(FILE *fp, struct myRecords table, char buffer[])
{
	int counter = 0;
	while(feof(fp))
	{
		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);
		++counter;
	}
	fclose(fp);
}

Open in new window

0
Comment
Question by:reesee324
2 Comments
 
LVL 30

Accepted Solution

by:
Zoppo earned 500 total points
ID: 35149766
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,

ZOPPO
0
 

Author Comment

by:reesee324
ID: 35149941
Okay thanks! Sometimes you just need a new set of eyes :)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now