ok so im trying to get my line of text file working with my file input. the Last part of my text file has a name of an event with spaces which I want to include those spaces so I needed a getline. apparently for some reason my getline function thats built in wasnt working so I made a new fgetline function that does the same thing and put it in my code. now im getting some weird error and im confused. any clues? list of files in order txt file, main, .cpp, .h, errors. thanks in advance!

842 M C 20.00 15 2 250 10.00 UC RosebudTheatre 90 One Mike Stand
990 E C 20.00 19 2 1250 10.00 TX TexasHall 75 Maverick Speaker Series
554 C N 16.45 30 1 35 0.00 UC PaloDuraLounge 60 Global Grounds Coffee Hour
318 E C 18.00 3 4 350 0.00 NH 100 75 Engineering Speaker Series
842 M C 20.00 16 4 250 10.00 UC RosebudTheatre 90 One Mike Stand
4 V N 9.00 26 4 2000 0.00 LIB LibraryMall 240 The Big Event
868 M N 10.00 2 4 600 0.00 SAC 108 360 3 Art Glass Sale
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> 
#include <ctype.h>
#include "UTAevent.h"


using namespace std;

#define TRUE 1
#define FALSE 0
#define EVENTMAX 10
#define EVENTMIN 0

int main()
{
	int answer, index=0;

	int newnumber, newsize, newlength, newpredict, newmonth, newday, newgoal, newtarget, menu;
	float newcost, newtime, newtotalCost;
	char newbuilding[75], newname[75], newroom[25], newtype, newpurpose;
	char tstr[75];
	int tstrcount = 75;
	enum goal;

	UTAevent Event[EVENTMAX];

	FILE *fp;
	std::cout<<
		"\n++++++++++ Event Registry ++++++++++\n\n"
		"This program is built to help the user with\n"
		"sort, searching, and printing school events\n"
		"that are going on around their school, home, or\n"
		"business. Due to limited memory, you are only\n"
		"allowed to have a maximum of 10 events. This\n"
		"will fix this in the next update.\n\n";
	if(( fp = fopen("uta.txt", "r")) == NULL){
		std::cout<<
			"Input file could not be opened!\n";
	}
	while (!feof(fp)){
		while(index > EVENTMIN && index < EVENTMAX){
		fscanf(fp, "%d %c %c %f %d %d %d %f %s %s %d", &newnumber, &newpurpose, &newtype, &newtime, &newday, &newmonth, &newsize, &newcost, &newbuilding, &newroom, &newlength);
		Event[index].fgetline(fp, tstr, tstrcount);
		strcpy(newname, tstr);

		Event[index].set_number(newnumber);
		Event[index].set_purpose(newpurpose);
		Event[index].set_type(newtype);
		Event[index].set_cost(newcost);
		Event[index].set_day(newday);
		Event[index].set_month(newmonth);
		Event[index].set_size(newsize);
		Event[index].set_time(newtime);
		Event[index].set_building(newbuilding);
		Event[index].set_room(newroom);
		Event[index].set_length(newlength);
		Event[index].set_name(newname);
		index++;
		}
	}

	while(menu = true){
		std::cout<< 
			"\n++++++++++++ Main Menu ++++++++++++\n\n"
			"1:\t\tSort\n"
			"2:\t\tSearch\n"
			"3:\t\tPrint the data in the array\n"
			"4:\t\tEnd the program\n"
			"\n\nPlease choose the number associated with your option.\n";
		cin>>answer;
		if (answer == 1){			// Sort
			std::cout<< 
				"\n++++++++++ Sort the event by ++++++++++\n\n"
				"1:\t\tcode\n"
				"2:\t\tname\n"
				"\n\n Please choose the number associated with your option.\n";
			cin>>answer;
			if (answer == 1){

			}
			if (answer == 2){
			
			}
			answer =0;
		}
		else if (answer == 2){		// Search
			std::cout<< 
				"\n++++++++ Search for event by ++++++++\n\n"
				"1:\t\tdate\n"
				"2:\t\tpurpose\n"
				"\n\n Please choose the number associated with your option.\n";
			cin>>answer;
			if (answer == 1){

			}
			if (answer == 2){
			
			}
			answer =0;
		}
		else if (answer == 3){		// Print the event
			int count = index;
			for (index = 0; index < count; index++){
				std::cout<< 
					"\n++++++++ Search for event by ++++++++\n\n"
					"1:\t\tdate\n"
					"2:\t\tpurpose\n"
					"\n\n Please choose the number associated with your option.\n";				
			}
		}
		else if (answer == 4){		// END PROGRAM
			std::cout<<
				"Thank you for using this program!\n";
			menu = false;
		}
	}
	return 0;
}
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> 
#include <ctype.h>
#include "UTAevent.h"

UTAevent::UTAevent()
{
	number = 0;
	type = ' ';
	purpose = ' ';
	time = 00.00;
	day = 0;
	month = 0;
	size = 0;
	cost = 0.00;
	length = 0;
	totalCost = 0.0;
}
void UTAevent::display() const{
	std::cout << "EVENT\n";
}
bool UTAevent::set_totalCost(float tot){
	if (tot >= 0){
		float addcost = tot;
		totalCost = totalCost + tot;
		return true;
	}
	else
		return false;
}
bool UTAevent::set_number(int num){
	int answer = num;
	if (answer == 842 || answer == 110 || answer == 120 || answer == 130 || answer == 140 || answer == 500 || answer == 803 || answer == 810 || answer == 874 || answer == 990 || answer == 318 || answer == 337 || answer == 301 || answer == 554 || answer == 868 || answer == 935 || answer == 4 || answer == 8 || answer == 10){
		number = num;
		return true;
	}
	else
		return false;
}
char UTAevent::set_name(char *nam){
	name[ strlen(nam)+1];
	strcpy(name , nam);
	return true;
}
bool UTAevent::set_type(char typ){
	char charanswer = typ;
	if (charanswer == 'c' || charanswer == 'C'){
		type = 'C';
		return true;
	}
	else if (charanswer == 'S'|| charanswer == 's'){
		type = 'S';
		return true;
	}
	else if (charanswer == 'P'|| charanswer == 'p'){
		type = 'P';
		return true;
	}
	else if (charanswer == 'N'|| charanswer == 'n'){
		type = 'N';
		return true;
	}
	else if (charanswer == 'D'|| charanswer == 'd'){
		type = 'D';
		return true;
	}
	else if (charanswer == 'l'|| charanswer == 'L'){
		type = 'L';
		return true;
	}
	else if (charanswer == 'b'|| charanswer == 'B'){
		type = 'B';
		return true;
	}
	else if (charanswer == 'o'|| charanswer == 'O'){
		type = 'O';
		return true;
	}
	else
		return false;
}
bool UTAevent::set_purpose(char purp){
	char charanswer = purp;
	if (charanswer == 'F' || charanswer == 'f'){
		purpose = 'F';
		return true;
	}
	else if (charanswer == 'm'|| charanswer == 'M'){
		purpose ='M';
		return true;
	}
	else if (charanswer == 'C'|| charanswer == 'c'){
		purpose ='C';
		return true;
	}
	else if (charanswer == 'S'|| charanswer == 's'){
		purpose ='S';
		return true;
	}
	else if (charanswer == 'v'|| charanswer == 'V'){
		purpose ='V';
		return true;
	}
	else if (charanswer == 'l'|| charanswer == 'L'){
		purpose ='L';
		return true;
	}
	else if (charanswer == 'E'|| charanswer == 'e'){
		purpose ='E';
		return true;
	}
	else if (charanswer == 'A'|| charanswer == 'a'){
		purpose ='A';
		return true;
	}
	else if (charanswer == 'O'|| charanswer == 'o'){
		purpose ='O';
		return true;
	}
	else if (charanswer == 'P'|| charanswer == 'p'){
		purpose ='P';
		return true;
	}
	else
		return false;
}
bool UTAevent::set_time(float tim){
	int hrpart = (int)tim;
	int minpart = ((int)(tim*100)%100);
	if ((hrpart <= 24 || hrpart >=0) && (minpart <=60 || minpart >=0)){
		if (hrpart ==24&& minpart==0){
			return  true;
			time = tim;
		}
		else if(hrpart<24)
		{
			return true;
			time = tim;
		}
		else{
			return false;
		}
	}
	else{
		return false;
	}
}
bool UTAevent::set_day(int days){
	if (days < 0 && days >= 31){
		day = days;
		return true;
	}
	return false;
}
bool UTAevent::set_month(int mon){
	if (mon > 0 && mon <= 12){
		month = mon;
		return true;
	}
	return false;
}
bool UTAevent::set_size(int siz){
	if (siz >= 0 ){
		size = siz;
		return true;
	}
	return false;
}
bool UTAevent::set_cost(float cos){
	if (cos >=0 ){
		cost = cos;
		return true;
	}
	return false;
}
char UTAevent::set_building(char *bui){
	building[ strlen(bui) + 1];
	strcpy(building, bui);
	return true;
}
char UTAevent::set_room(char *roo){
	room[ strlen(roo) + 1];
	strcpy(room, roo);
	return true;
}
bool UTAevent::set_length(int len){
	if (len >= 0 && len <=60){
		length = len;
		return true;
	}
	return false;
}
bool UTAevent::set_predict(int pre){
	return true;
}
UTAevent::~UTAevent(void)
{
	delete [] name;
}
int fgetline(FILE *fp, char s[], int lim) {
    char *t;
    int c, len=lim;

    t = s;

    while (--lim>1 && (c=getc(fp)) != EOF && c != '\n')
        *s++ = c;
    if (c == '\n')
        *s++ = c;
    else if (lim == 1) {
	*s++ = '\n';
	fprintf(stderr, "WARNING. fgetline: Line too long, splitted.\n");
    }
    *s = '\0';
    return s - t;
}
using namespace std;
#ifndef HEADER_FILE_H
#define HEADER_FILE_H

class UTAevent
{
public:
	UTAevent();
	//PRECONDITION: none
	//
	//POSTCONDITION: The data members of the object have
	//				 been initialized to default values.
	~UTAevent();
	//PRECONDITION: none
	//
	//POSTCONDITION: the employee is properly destroyed.
	//
	bool set_number(int num);
	//PRECONDITION: num must be a positive num that is associated with a
	//				specific event.
	//POSTCONDITION: number has been set to num.
	//
	char set_name(char *nam);
	//PRECONDITION: none
	//
	//POSTCONDITION: the name associated with a specific event has been set.
	//
	bool set_type(char typ);
	//PRECONDITION: typ must be of one of the specified event types.
	//
	//POSTCONDITION: the character code of the event type has been set.
	//
	bool set_purpose(char purp);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, purp has been added. if
	//				the return value is false, purp was not added.
	bool set_time(float tim);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, tim has been added. if
	//				the return value is false, tim was not added.
	bool set_day(int days);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, days has been added. if
	//				the return value is false, days was not added.
	bool set_month(int mon);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, mon has been added. if
	//				the return value is false, mon was not added.
	bool set_size(int siz);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, siz has been added. if
	//				the return value is false, siz was not added.
	bool set_cost(float cos);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, cos has been added. if
	//				the return value is false, cos was not added.
	char set_building(char *bui);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, *bui has been added. if
	//				the return value is false, *bui was not added.
	char set_room(char *roo);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, roo has been added. if
	//				the return value is false, roo was not added.
	bool set_length(int len);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, len has been added. if
	//				the return value is false, len was not added.
	bool set_predict(int pre);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, pre has been added. if
	//				the return value is false, pre was not added.
	bool set_totalCost(float tot);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, tot has been added. if
	//				the return value is false, tot was not added.
	int get_number() const { return number; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event number is returned
	//
	const char * get_name() const { return name; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event name is returned
	//
	char get_type() const { return type; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event type is returned
	//
	char get_purpose() const { return purpose; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event purpose is returned
	//
	float get_time() const { return time; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event time is returned
	//
	int get_day() const { return month; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the day of the event is returned
	//
	int get_month() const { return month; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event month is returned
	//
	int get_size() const { return size; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event size is returned
	//
	float get_cost() const { return cost; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the cost of the event is returned
	//
	const char * get_building() const { return building; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the building is returned
	//
	const char * get_room()const { return room; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the room number is returned
	//
	int get_length() const { return length; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the length is returned
	//
	int get_predict() const { return predict;}
	//PRECONDITION: none
	//
	//POSTCONDITION: the attendance prediction is returned
	//
	float get_totalCost() const { return totalCost;}
	//PRECONDITION: none
	//
	//POSTCONDITION: the total cost is returned
	//
	void display() const;
	//PRECONDITION: none
	//
	//POSTCONDITION: the id and number in inventory
	//				have been displayed on standard output
	int fgetline(FILE *fp, char s[], int lim);
	//PRECONDITION: none
	//
	//POSTCONDITION: whats left from the line will be stored in a char array
	//				of s with a size of lim.
	#endif //HEADER_FILE_H
private:
	int number, size, length, predict;
	char name[75];
	unsigned month : 4;
	unsigned day : 5; 
	char room[25];
	char type, purpose; 
	char building[75];
	float cost, time, totalCost;
};
Error	8	error LNK2001: unresolved external symbol "public: int __thiscall UTAevent::fgetline(struct _iobuf *,char * const,int)" (?fgetline@UTAevent@@QAEHPAU_iobuf@@QADH@Z)	UTA.obj	
Error	9	fatal error LNK1120: 1 unresolved externals	C:\Users\Tyler\Documents\Visual Studio 2005\Projects\Lab 4\Debug\Lab 4.exe	1

Recommended Answers

All 2 Replies

You declare fgetline as a member function of the UTAevent class.
Except, when you define it you do not tell the compiler that the definition is part of the UTAevent class:

int fgetline(FILE *fp, char s[], int lim)
{
    // ...
}

Look at the other functions declared in UTAevent class, how are they defined in the .cpp file? What is the difference between those functions and your fgetline.

commented: nice catch +21

wow thanks. yes that fixed it. >< need a coke or something missing that kind of error! thanks for the help

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.