473,320 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

problem reading from a file

SB
Hello. I have an input file which is laid out in the following manner...
Name
Day 1
am time 1
am time 2
appointment
pm time 1
pm time 2
appointment
Day 2
am time 1....

This is repeated for three people, for five days. So for each person (three
names), there is five days worth of the am/pm time 1/2, appointment data.
The problem I'm having is reading each line and storing it's value in the
corresponding person's class member. I have a Doctor class (which represents
a person in the file) and that class has a five element array of a Day class
(each day's data gets its own Day object). I also have a Schedule class
which contains an array of three Doctor classes. Here is the code for
reading the input file and populating the objects data members...

void Schedule::loadSchedule(ifstream& inputFile)
{
string temp; // temp variable for storing each line read from file
int i; // for doc index
int j; // for day index

// read from input file and populate each doctors data
for (i = 0; i < NUMBER_OF_DOCTORS; i++)
{
getline(inputFile, temp);
doc[i].setName(temp);
cout<<endl<<"name is <"<<doc[i].getName()<<">";
j = 0; // reset day counter for each doctor
for (j; j < NUMBER_OF_DAYS; j++)
{
// make sure we haven't accidentally read beyond the end of the file
if (inputFile.eof())
{
cout<<"End of File has been reached while reading the input
file."<<endl;
exit(1);
}
getline(inputFile, temp);
doc[i].setDay(i, temp);
cout<<endl<<"day is <"<<doc[i].getDay(j)<<">";
getline(inputFile, temp);
doc[i].setAmStart(i, temp);
cout<<endl<<"am start for "<<doc[i].getDay(j)<<" is
<"<<doc[i].getAmStart(j)<<">";
getline(inputFile, temp);
doc[i].setAmEnd(i, temp);
cout<<endl<<"am end for "<<doc[i].getDay(j)<<" is
<"<<doc[i].getAmEnd(j)<<">";
getline(inputFile, temp);
doc[i].setAmAppt(i, temp);
cout<<endl<<"am appointment for "<<doc[i].getDay(j)<<" is
<"<<doc[i].getAmAppt(j)<<">";
getline(inputFile, temp);
doc[i].setPmStart(i, temp);
cout<<endl<<"pm start for "<<doc[i].getDay(j)<<" is
<"<<doc[i].getPmStart(j)<<">";
getline(inputFile, temp);
doc[i].setPmEnd(i, temp);
cout<<endl<<"pm end for "<<doc[i].getDay(j)<<" is
<"<<doc[i].getPmEnd(j)<<">";
getline(inputFile, temp);
doc[i].setPmAppt(i, temp);
cout<<endl<<"pm appointment for "<<doc[i].getDay(j)<<" is
<"<<doc[i].getPmAppt(j)<<">";
}
}

// close the file
inputFile.close();
}

Here is the output from the cout statement in the above code...

name is <Andrew Jones>
day is <Monday>
am start for Monday is <9>
am end for Monday is <12>
am appointment for Monday is <Lecture>
pm start for Monday is <13>
pm end for Monday is <16>
pm appointment for Monday is <Free>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
name is <Eric Roberts>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <Tuesday>
am start for Tuesday is <9>
am end for Tuesday is <12>
am appointment for Tuesday is <Free>
pm start for Tuesday is <13>
pm end for Tuesday is <16>
pm appointment for Tuesday is <Surgery>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
name is <Mathew Hayden>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <Wednesday>
am start for Wednesday is <9>
am end for Wednesday is <12>
am appointment for Wednesday is <Free>
pm start for Wednesday is <13>
pm end for Wednesday is <16>
pm appointment for Wednesday is <Lecture>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>
day is <>
am start for is <>
am end for is <>
am appointment for is <>
pm start for is <>
pm end for is <>
pm appointment for is <>

The problem is the empty less than/greater than signs. I don't know why data
is not being populated for those values. Is it the way I'm using getline or
something? Interestingly, the less than/greater than signs that do contain
data are all correct. I matched them up with the data in the input file and
it matches. So the values that are getting populated are being done in the
correct order. Can anyone see what I'm doing wrong here? Any help is
appreciated!

Thank you in advance!
Jul 22 '05 #1
3 2176
On Sun, 11 Apr 2004 20:56:32 -0400, "SB" <vo******@hotmail.com> wrote:

Without declarations for the data you're working with, folks aren't too
likely to waste their time guessing as to what your problem might be.

I'd suggest re-posting with a /small/ version of your program that exhibits
the erroneous behavior, driven by a /small/ input file that you can show
the exact contents of (I couldn't tell if your input file details were a
description or data or what...but I guessed they were just a description),
and then just show enough of the output to indicate one or two examples of
the failure.

Thanks,
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #2
I just noticed you also have all these calls to setThisAndThat(). Include
them too. IOW, show a complete program if you want prompt, useful feedback.
Thanks,
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #3
SB
Thanks, but I actually figured it out myself. I mistakenly used variable i
instead of j for the setXXX function calls. Although, the output that I
posted was the entire output.

Thanks anyways!

"Leor Zolman" <le**@bdsoft.com> wrote in message
news:in********************************@4ax.com...
On Sun, 11 Apr 2004 20:56:32 -0400, "SB" <vo******@hotmail.com> wrote:

Without declarations for the data you're working with, folks aren't too
likely to waste their time guessing as to what your problem might be.

I'd suggest re-posting with a /small/ version of your program that exhibits the erroneous behavior, driven by a /small/ input file that you can show
the exact contents of (I couldn't tell if your input file details were a
description or data or what...but I guessed they were just a description),
and then just show enough of the output to indicate one or two examples of
the failure.

Thanks,
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
8
by: Brandon McCombs | last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm trying here. I have a C++ book by Deitel and Deitel that says I can use fstream File("data.dat", ios::in | ios::out |...
1
by: Magnus Lycka | last post by:
I'm trying to read standard out in a process started with popen2 in a non-blocking way. (Other good ways of doing this than the one I tried are appreciated.) I've tried to dumb down my code to...
7
by: Thomas Sourmail | last post by:
Hi, I hope I am missing something simple, but.. here is my problem: I need my program to check the last column of a file, as in : a b c d target ref 0 0 0 0 1 a 1 0 0 0 1.5 b 2 0 0 0 2 c
2
by: Sabin Finateanu | last post by:
Hi I'm having problem reading a file from my program and I think it's from a procedure I'm using but I don't see where I'm going wrong. Here is the code: public bool AllowUsage() { ...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
0
by: Fabrice | last post by:
Hello, (Alain) Tis is a part of my code to retrieve text from hastable in memory cache, by reading (befor) a resources file. Thanks for your help. /1/ The resources file * I have create a...
5
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
10
by: oktayarslan | last post by:
Hi all; I have a problem when inserting an element to a vector. All I want is reading some data from a file and putting them into a vector. But the program is crashing after pushing a data which...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.