C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 5th, 2014, 02:59 PM
ladytexasbear ladytexasbear is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2014
Posts: 1 ladytexasbear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 26 sec
Reputation Power: 0
File IO - Input binary file output screen ascii

When I run this code I get

Worker's Full Name: 0x22d7c4 0x222d7f8
ID number: 0x22d82c
Date Hired: 0x22d85c
Rate of pay: 0@0

or (for another record)

Worker's Full Name: 0x22e404 0x22e438
ID number 0x22e46c
Date Hired: 0x22e49c
Rate of pay: 1.12104e-043 @ 3.20735e-039

How do I make it read the "human" version instead?

Here is the code:

struct Workers
{
string fName[13];
string lName[13];
string ident[12];
string dateHired[9];
float payRate;
float hoursWorked;

void ShowMe();

};

//Function Prototypes
void pause(char * = const_cast<char*>(""),int key=0x00);
//Global Variables and constants (Be prepared to justify why they are necessary)

int main()
{
//Declare variables and constants
Workers Employees[100];
ifstream empRec;

//Open file(s), if needed
empRec.open(".\\Lab5.bin",ios::in|ios::binary);

if(empRec.fail())
{
cout<<"The Employee information file could not be found! Please find the file, "
<<"place it in the same directory as the program, re-launch the program and try again!\n";

return 999;
}
//Get data
int sub=0;

empRec.read(reinterpret_cast<char *>(&Employees[sub]),sizeof(Employees[sub]));


while(!empRec.eof())
{
empRec.read(reinterpret_cast<char *>(&Employees[sub]),sizeof(Employees[sub]));

sub++;
}



//Processing operations required by the problem specification

//Produce output (information)
for(int sub=0;sub<100;sub++)
{
cout<<sub+1<<":\n";

Employees[sub].ShowMe();
}

//Close file(s), if they were opened
empRec.close();

pause();
return 0;
} //end main()

//Function Definitions
void pause(char* prompt,int key)
{
char ch;
if((strcmp(prompt,"")==0) || (key==0x00))
{
printf("Press ANY key to continue..");
do
{
}while(getch()=='\0');
}
else
{
printf("Press %s key to continue..",prompt);

do
{
ch=getch();
}while(ch != key);
}
printf("\n\n");
return;
}

void Workers::ShowMe()
{
cout<<"Worker's Full Name: ";
cout<<fName<<" "<<lName<<endl;
cout<<"ID number: ";
cout<<ident<<endl;
cout<<"Date Hired: ";
cout<<dateHired<<endl;
cout<<"Rate of pay: ";
cout<<payRate<<" @ "<<hoursWorked<<endl<<endl;


Thank you!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > File IO - Input binary file output screen ascii


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap