Solved

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

Posted on 2011-03-16
2
400 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 31

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Estimate porting issues. 9 122
Test against App 49 138
C hashtable library 3 107
Want to delete all my personal data 13 152
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

730 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