okay so idk why this isnt working but im having trouble reading from the text file. i know it looks rough im only showing the basic parts of what i really have to do for the project. can someone please help me?
this is the text file:
(id, lastname, firstname, position, age, salary)
Code:
11169 King, Leroy manager 60 45000.00
65765 Guilfour, Theresa clerk 32 24000.00
51432 Ieyoub, Kalil salesman 48 37000.00
12768 Cooper, Scott salesman 50 20800.00
19180 Newman, Hank manager 56 40000.00
31216 Fields, Lori maintenance 40 18000.00
32589 Andrews, Dana accountant 45 24000.00
43786 Palmer, Tom stockman 48 19000
48971 Baker, Kelly secretary 42 25000.00
56342 Beard, John salesman 55 43000.00
68754 Shelton, Bob manager 60 46000.00
74753 Gaston, Chad stockman 60 19000.00
85154 Adams, Harry salesman 55 41000.00
71654 Bonvillion, Cheri secretary 40 23000.00
69876 Grimes, Gary carpenter 80 25000.00
it compiles fine but when i a.out it gives me this:
Code:
11169
K@«ªª*
i9¡ÿ
32622
2.31779e-310
and nothing else.
this is the codeps: ignore the "Binary" parameters....i have to make it binary later but i need to read it in correctly before i can convert to binary....also this is a very simplified version of my code the actual code is about 700 lines but i blocked it all as comments so i left most of the code out to make it more readable)
Code:
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdlib>
using namespace std;
struct PERSON
{
int EmployeeID;
char LastName[12];
char FirstName[8];
char EmployeeTitle[12];
int EmployeeAge;
double EmployeeSalary;
};
//prototypes
int FillData(PERSON person[MAX], ifstream & inFile, fstream &Binary);
int main()
{
PERSON person[MAX]; //struct
ifstream inFile; //input file
inFile.open("text.data");
if(inFile.fail())
{
cout<<"\n\nError: cannot open text file"<<endl<<endl;
exit(1);
}
//PrintWelcome();
//Fill Data from File
int ct = FillData(person, inFile, Binary);
inFile.close();
return 0;
}
//**************************************************************
int FillData(PERSON person[MAX], ifstream & inFile, fstream & Binary)
{
int count=0;
while(inFile >> person[count].EmployeeID)
{
cout<<person[count].EmployeeID<<endl;
inFile>> person[count].LastName[12];
cout<< person[count].LastName;
inFile>> person[count].FirstName[8];
cout<< person[count].FirstName<<endl;
inFile>> person[count].EmployeeTitle[12];
cout<< person[count].EmployeeTitle<<endl;
inFile>> person[count].EmployeeAge;
cout<<person[count].EmployeeAge<<endl;
inFile>> person[count].EmployeeSalary;
cout<<person[count].EmployeeSalary<<endl<<endl;
count ++;
}
return count;
}