473,507 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

while can't go to the 2nd record.

Wen
Hallo,
Can someone tell me why my while doenst read the second, third.... record?
(This's a part of my code.)
I've looked for it in the books and on internet, but juist don't see the
probleem.
TI@
Wen
int klantNr, access;
Client MutatieRec, MasterRec;
OpenBestand(access);

LeesMutatie( MutatieRec, klantNr);
while( MutatieRec.klantNr !=HV) //HV is defined as 99999
{
cout<<MutatieRec.klantNr;
LeesMutatie( MutatieRec, klantNr);
}
cin.get();

--

Met vriendelijke groet,

Wen
Jul 22 '05 #1
16 1348
"Wen" <We************@hccnet.nl> wrote...
Can someone tell me why my while doenst read the second, third.... record?
(This's a part of my code.)
I've looked for it in the books and on internet, but juist don't see the
probleem.
TI@
Wen
int klantNr, access;
Client MutatieRec, MasterRec;
OpenBestand(access);

LeesMutatie( MutatieRec, klantNr);
while( MutatieRec.klantNr !=HV) //HV is defined as 99999
{
cout<<MutatieRec.klantNr;
LeesMutatie( MutatieRec, klantNr);
}
cin.get();


AFAICT, 'LeesMutatie' has not been defined in this program. Could it
be the source why it's not working? Post complete code, and not some
fragments that are impossible to validate.
Jul 22 '05 #2
Wen wrote:
Hallo,
Can someone tell me why my while doenst read the second, third.... record?
(This's a part of my code.)

Modify the code as show below. If it prints "Mutatie.klantNr is equal to
HV", then problem is not in the code fragment you provided.

// ---------------------------------------------------------
int*klantNr,*access;
Client*MutatieRec,*MasterRec;

if ( MutatieRec.klantNr == HV ) {
cout << "Mutatie.klantNr is equal to HV" << endl ;
}

OpenBestand(access);

if ( MutatieRec.klantNr == HV ) {
cout << "Mutatie.klantNr is equal to HV" << endl ;
}
LeesMutatie(*MutatieRec,*klantNr);
if ( MutatieRec.klantNr == HV ) {
cout << "Mutatie.klantNr is equal to HV" << endl ;
}
while(*MutatieRec.klantNr*!= HV)**//HV*is*defined*as*99999
{
cout << MutatieRec.klantNr;
LeesMutatie(*MutatieRec,*klantNr);
}
cin.get();
// ---------------------------------------------------------

--
CrayzeeWulf
Jul 22 '05 #3
Wen
Well, I can't post all my code, it's really to much. But I'd select this
part, so that you can can see what's wrong with it.
Regards,
Wen

#include <iostream>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>

const int HV= 99999;

struct Client
{
int klantNr;
char soort[2];
char naam[26];
char adres[26];
char postcode[7];
char plaats[16];
int bankNr;
int giro;
char mutcode[2];
char tariefAfspr[2];
};

using namespace std;
void OpenBestand(int& access);
void LeesMutatie(Client & MutatieRec, int & klantNr);

int main()
{
int klantNr, access;
Client MutatieRec, MasterRec;
OpenBestand(access);

LeesMutatie( MutatieRec, klantNr);
while( MutatieRec.klantNr !=HV)
{
cout<<MutatieRec.klantNr;
LeesMutatie( MutatieRec, klantNr);
}
cin.get();
}

void LeesMutatie(Client & MutatieRec, int & klantNr)
{
ifstream mutatie ("mutatie.csv");
char puntkomma = ';';

mutatie >> MutatieRec.klantNr >> puntkomma;
mutatie.getline(MutatieRec.soort, 2, ';');
mutatie.getline(MutatieRec.naam, 26, ';');
mutatie.getline(MutatieRec.adres, 26, ';');
mutatie.getline(MutatieRec.postcode,7, ';');
mutatie.getline(MutatieRec.plaats, 16, ';');
mutatie >> MutatieRec.bankNr >> puntkomma;
mutatie >> MutatieRec.giro >> puntkomma;
mutatie.getline(MutatieRec.mutcode, 2, ';');
mutatie.getline(MutatieRec.tariefAfspr, 2, ';');
if (mutatie.eof())
MutatieRec.klantNr = HV;
}

void OpenBestand(int& access)
{
ifstream constant, klant, mutatie;

constant.open("constant.csv");
if(constant.fail())
{
cerr << "Het constantenbestand kon niet worden geopend" << endl;
access = 0;
}

klant.open("klant.dat", ios::binary );
if(klant.fail())
{
cerr << "Het klantenbestand kon niet worden geopend" << endl;
access = 0;
}

mutatie.open("mutatie.csv");
if(mutatie.fail())
{
cerr << "Het mutatiebestand kon niet worden geopend" << endl;
access = 0;
}
}
"Victor Bazarov" <v.********@comAcast.net> schreef in bericht
news:5IoIb.79856$VB2.162883@attbi_s51...
"Wen" <We************@hccnet.nl> wrote...
Can someone tell me why my while doenst read the second, third.... record? (This's a part of my code.)
I've looked for it in the books and on internet, but juist don't see the
probleem.
TI@
Wen
int klantNr, access;
Client MutatieRec, MasterRec;
OpenBestand(access);

LeesMutatie( MutatieRec, klantNr);
while( MutatieRec.klantNr !=HV) //HV is defined as 99999
{
cout<<MutatieRec.klantNr;
LeesMutatie( MutatieRec, klantNr);
}
cin.get();


AFAICT, 'LeesMutatie' has not been defined in this program. Could it
be the source why it's not working? Post complete code, and not some
fragments that are impossible to validate.

Jul 22 '05 #4
Wen
10001;A;Ahold;Kruidenierstraat 2;1234AA;Zaandam;123456789;1234567;M;X
10002;D;Albert Heijn;Industrieterrein
5;1111BN;Zaandam;341259878;1254444;V;Q
10003;E;Kruidvat;Holtenbroek 123;2300CB;Schiedam;331215171;3459770;T;S
10004;F;Blokker;Amstelveensweg 331;1111SH;Diemen;812355565;9002352;M;H
10005;A;Houtman;Rotterdamsvaart 123;3800ET;Gouda;567568456;3334444;V;P
10006;E;Visa;Rodekruisweg 23;1156SH;Diemen;80335658;7456891;T;O
10007;B;Hema;Zilverkruisweg 523;5056AA;Apeldoorn;753356564;7456891;T;O
These are information form the "mutatie.csv" file.

"Victor Bazarov" <v.********@comAcast.net> schreef in bericht
news:5IoIb.79856$VB2.162883@attbi_s51...
"Wen" <We************@hccnet.nl> wrote...
Can someone tell me why my while doenst read the second, third.... record? (This's a part of my code.)
I've looked for it in the books and on internet, but juist don't see the
probleem.
TI@
Wen
int klantNr, access;
Client MutatieRec, MasterRec;
OpenBestand(access);

LeesMutatie( MutatieRec, klantNr);
while( MutatieRec.klantNr !=HV) //HV is defined as 99999
{
cout<<MutatieRec.klantNr;
LeesMutatie( MutatieRec, klantNr);
}
cin.get();


AFAICT, 'LeesMutatie' has not been defined in this program. Could it
be the source why it's not working? Post complete code, and not some
fragments that are impossible to validate.

Jul 22 '05 #5
Wen wrote:

void LeesMutatie(Client & MutatieRec, int & klantNr)
{
ifstream mutatie ("mutatie.csv");
char puntkomma = ';';

This will open the file "mutatie.csv" again and again every time
LessMutatie() is called. So you will only read the first record.

Later,
--
CrayzeeWulf
Jul 22 '05 #6
Wen
ok, so I'd put the ';' away. I'll try that.
Thank you.
Wen

"CrayzeeWulf" <cr*********@nospam.gnudom.org> schreef in bericht
news:M4*******************@twister.socal.rr.com...
Wen wrote:

void LeesMutatie(Client & MutatieRec, int & klantNr)
{
ifstream mutatie ("mutatie.csv");
char puntkomma = ';';

This will open the file "mutatie.csv" again and again every time
LessMutatie() is called. So you will only read the first record.

Later,
--
CrayzeeWulf

Jul 22 '05 #7
Wen
I'd try this, but it doens't work neither.
Regards,
Wen

void LeesMutatie(Client & MutatieRec, int& klantNr)
{
ifstream mutatie ("mutatie.csv");
char komma;

mutatie >> MutatieRec.klantNr >> komma;
mutatie.getline(MutatieRec.soort, 2, komma);
mutatie.getline(MutatieRec.naam, 26, komma);
mutatie.getline(MutatieRec.adres, 26, komma);
mutatie.getline(MutatieRec.postcode,7, komma);
mutatie.getline(MutatieRec.plaats, 16, komma);
mutatie >> MutatieRec.bankNr >> komma
MutatieRec.giro >> komma;
mutatie.getline(MutatieRec.mutcode, 2, komma);
mutatie.getline(MutatieRec.tariefAfspr, 2, komma);
if (mutatie.eof())
MutatieRec.klantNr = HV;
}
"CrayzeeWulf" <cr*********@nospam.gnudom.org> schreef in bericht
news:M4*******************@twister.socal.rr.com... Wen wrote:

void LeesMutatie(Client & MutatieRec, int & klantNr)
{
ifstream mutatie ("mutatie.csv");
char puntkomma = ';';

This will open the file "mutatie.csv" again and again every time
LessMutatie() is called. So you will only read the first record.

Later,
--
CrayzeeWulf

Jul 22 '05 #8
Wen wrote:
I'd try this, but it doens't work neither.
Regards,
Wen

void LeesMutatie(Client & MutatieRec, int& klantNr)
{
ifstream mutatie ("mutatie.csv");

Wen,

Its not the comma. The problem is that you are creating an ifstream instance
named "mutatie" every time you call LessMutatie(). Every the first line of
this function is executed, you create an ifstream instance and open the
file "mutatie.csv". At this point, the rest of the function reads the file
from the very beginning.

In order to fix this, you will have to redesign your code to make sure that
you do not open the file on every call to LessMutatie(). For example, you
can try opening the file outside LessMutatie() and pass it a reference to
an ifstream instance:

// -------------------------------------------------------------------------
void LeesMutatie(ifstream& input_stream, Client & MutatieRec, int &klantNr);

int main()
{
int klantNr, access;
Client MutatieRec, MasterRec;
OpenBestand(access);
ifstream mutatie( "mutatie.csv" ) ;

LeesMutatie( mutatie, MutatieRec, klantNr);
while( MutatieRec.klantNr != HV )
{
cout << MutatieRec.klantNr << ":" << MutatieRec.soort << endl ;
LeesMutatie( mutatie, MutatieRec, klantNr);
}
cin.get();
}

void LeesMutatie(ifstream& mutatie, Client & MutatieRec, int &klantNr)
{
char puntkomma = ';';
if ( ! mutatie ) {
std::cout << "mutatie kaput." << endl ;
exit(1) ;
}
mutatie >> MutatieRec.klantNr >> puntkomma;
mutatie.getline(MutatieRec.soort, 2, ';');
mutatie.getline(MutatieRec.naam, 26, ';');
mutatie.getline(MutatieRec.adres, 26, ';');
mutatie.getline(MutatieRec.postcode,7, ';');
mutatie.getline(MutatieRec.plaats, 16, ';');
mutatie >> MutatieRec.bankNr >> puntkomma;
mutatie >> MutatieRec.giro >> puntkomma;
mutatie.getline(MutatieRec.mutcode, 2, ';');
mutatie.getline(MutatieRec.tariefAfspr, 2, ';');

if ( mutatie.eof() )
MutatieRec.klantNr = HV;
}
// -------------------------------------------------------------------------

There are other problems with the original LessMutatie() besides the
reopening of "mutatie.csv". But that is a separate issue that you will have
to figure out.

--
CrayzeeWulf
Jul 22 '05 #9
Wen wrote:
I'd try this, but it doens't work neither.
Regards,
Wen

void LeesMutatie(Client & MutatieRec, int& klantNr)
{
ifstream mutatie ("mutatie.csv");

Wen,

Its not the comma. The problem is that you are creating an ifstream instance
named "mutatie" every time you call LessMutatie(). Every time the first line
of this function is executed, you create an ifstream instance and open the
file "mutatie.csv". At this point, the rest of the function reads the file
from the very beginning.

In order to fix this, you will have to redesign your code to make sure that
you do not open the file on every call to LessMutatie(). For example, you
can try opening the file outside LessMutatie() and pass it a reference to
an ifstream instance:

// -------------------------------------------------------------------------
void LeesMutatie(ifstream& input_stream, Client & MutatieRec, int &klantNr);

int main()
{
int klantNr, access;
Client MutatieRec, MasterRec;
OpenBestand(access);
ifstream mutatie( "mutatie.csv" ) ;

LeesMutatie( mutatie, MutatieRec, klantNr);
while( MutatieRec.klantNr != HV )
{
cout << MutatieRec.klantNr << ":" << MutatieRec.soort << endl ;
LeesMutatie( mutatie, MutatieRec, klantNr);
}
cin.get();
}

void LeesMutatie(ifstream& mutatie, Client & MutatieRec, int &klantNr)
{
char puntkomma = ';';
if ( ! mutatie ) {
std::cout << "mutatie kaput." << endl ;
exit(1) ;
}
mutatie >> MutatieRec.klantNr >> puntkomma;
mutatie.getline(MutatieRec.soort, 2, ';');
mutatie.getline(MutatieRec.naam, 26, ';');
mutatie.getline(MutatieRec.adres, 26, ';');
mutatie.getline(MutatieRec.postcode,7, ';');
mutatie.getline(MutatieRec.plaats, 16, ';');
mutatie >> MutatieRec.bankNr >> puntkomma;
mutatie >> MutatieRec.giro >> puntkomma;
mutatie.getline(MutatieRec.mutcode, 2, ';');
mutatie.getline(MutatieRec.tariefAfspr, 2, ';');

if ( mutatie.eof() )
MutatieRec.klantNr = HV;
}
// -------------------------------------------------------------------------

There are other problems with the original LessMutatie() besides the
reopening of "mutatie.csv". But that is a separate issue that you will have
to figure out.

--
CrayzeeWulf
Jul 22 '05 #10
>
void LeesMutatie(Client & MutatieRec, int & klantNr)
{
ifstream mutatie ("mutatie.csv");


mutatie.cvs file is reopened on each call of LeesMutatie. Thus you read only
the begining of the file on each call.
You can fix the problem by initializing the input file stream in your main
and passing the ifstream as an argument to LeesMutatie as follow:

void LeesMutatie(const ifstream& mutatie, Client & MutatieRec, int &
klantNr);

int main()
{

// Some code....

ifstream mutatie ("mutatie.csv");
if ( !mutatie )
{
// Error could not open file!!!
// ...do something
}

while( !mutatie.eof() ) // You can now test for end of file here
{
LeesMutatie( mutatie, MutatieRec, klantNr);
cout<<MutatieRec.klantNr;
}

//...
}

void LeesMutatie(const ifstream& mutatie , Client & MutatieRec, int &
klantNr)
{
// Remove previous mutatie definition and initialization
// and use mutatie
}

Thierry
Jul 22 '05 #11
"Wen" <We************@hccnet.nl> wrote...
I'd try this, but it doens't work neither.
Regards,
Wen

void LeesMutatie(Client & MutatieRec, int& klantNr)
{
ifstream mutatie ("mutatie.csv");


Open this file once, outside this function, and pass it (by
reference) into this function, otherwise every time this func
returns the 'mutatie' stream gets _CLOSED_ and every time
you call this function again, it _REOPENS_ the stream. And,
of course, it reads the very first record again.

Do you understand what we are talking about?
Jul 22 '05 #12
[snip some other code]
void LeesMutatie(const ifstream& mutatie , Client & MutatieRec, int &


^^^^^ not const!!! you're reading the file, so it
is changed and I don't think it'll compile. do: ifstream & mutatie...

[snip]
Jul 22 '05 #13
Wen
Thank you so much for help!

I'd try your code, it also show 1 record after that comes the "mutatie
kaput." ,
and without this :
if ( ! mutatie ) {
std::cout << "mutatie kaput." << endl ;
exit(1) ;
}

it shows 10000 times the first record.
How come?
Regards
Wen
"CrayzeeWulf" <cr*********@nospam.gnudom.org> schreef in bericht
news:pI******************@twister.socal.rr.com...
Wen wrote:
I'd try this, but it doens't work neither.
Regards,
Wen

void LeesMutatie(Client & MutatieRec, int& klantNr)
{
ifstream mutatie ("mutatie.csv"); Wen,

Its not the comma. The problem is that you are creating an ifstream

instance named "mutatie" every time you call LessMutatie(). Every time the first line of this function is executed, you create an ifstream instance and open the
file "mutatie.csv". At this point, the rest of the function reads the file
from the very beginning.

In order to fix this, you will have to redesign your code to make sure that you do not open the file on every call to LessMutatie(). For example, you
can try opening the file outside LessMutatie() and pass it a reference to
an ifstream instance:

// ------------------------------------------------------------------------- void LeesMutatie(ifstream& input_stream, Client & MutatieRec, int &klantNr);
int main()
{
int klantNr, access;
Client MutatieRec, MasterRec;
OpenBestand(access);
ifstream mutatie( "mutatie.csv" ) ;

LeesMutatie( mutatie, MutatieRec, klantNr);
while( MutatieRec.klantNr != HV )
{
cout << MutatieRec.klantNr << ":" << MutatieRec.soort << endl ;
LeesMutatie( mutatie, MutatieRec, klantNr);
}
cin.get();
}

void LeesMutatie(ifstream& mutatie, Client & MutatieRec, int &klantNr)
{
char puntkomma = ';';
if ( ! mutatie ) {
std::cout << "mutatie kaput." << endl ;
exit(1) ;
}
mutatie >> MutatieRec.klantNr >> puntkomma;
mutatie.getline(MutatieRec.soort, 2, ';');
mutatie.getline(MutatieRec.naam, 26, ';');
mutatie.getline(MutatieRec.adres, 26, ';');
mutatie.getline(MutatieRec.postcode,7, ';');
mutatie.getline(MutatieRec.plaats, 16, ';');
mutatie >> MutatieRec.bankNr >> puntkomma;
mutatie >> MutatieRec.giro >> puntkomma;
mutatie.getline(MutatieRec.mutcode, 2, ';');
mutatie.getline(MutatieRec.tariefAfspr, 2, ';');

if ( mutatie.eof() )
MutatieRec.klantNr = HV;
}
// -------------------------------------------------------------------------
There are other problems with the original LessMutatie() besides the
reopening of "mutatie.csv". But that is a separate issue that you will have to figure out.

--
CrayzeeWulf

Jul 22 '05 #14
> > void LeesMutatie(const ifstream& mutatie , Client & MutatieRec, int &

^^^^^ not const!!! you're reading the file, so it
is changed and I don't think it'll compile. do: ifstream & mutatie...

[snip]

Your are right, my mistake.
Jul 22 '05 #15
On Tue, 30 Dec 2003 20:16:13 -0500, Thierry Miceli wrote:
ifstream mutatie ("mutatie.csv");
if ( !mutatie )
{
// Error could not open file!!!
// ...do something
}

while( !mutatie.eof() ) // You can now test for end of file here
{
LeesMutatie( mutatie, MutatieRec, klantNr);
cout<<MutatieRec.klantNr;
}


I wouldn't do this. You can only detect eof() inside LeesMutatie by seeing
that a read failed.

Do something like:

ifstream mutatie ("mutatie.csv");
if ( !mutatie )
{
// Error could not open file!!!
// ...do something
}

while( LeesMutatie( mutatie, MutatieRec, klantNr) ) {
cout<<MutatieRec.klantNr;
}

And modify LeesMutatie accordingly (it can simply return the stream object
reference).

HTH,
M4

Jul 22 '05 #16
Happy New Year, everyone.

Thank you once more. Finally I understand what you are talking about. And
with your help I've solved more my problems.

Best Regards,

Wen
Jul 22 '05 #17

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

Similar topics

33
3800
by: Diez B. Roggisch | last post by:
Hi, today I rummaged through the language spec to see whats in the for ... else: for me. I was sort of disappointed to learn that the else clauses simply gets executed after the loop-body -...
0
1753
by: lea | last post by:
I have two combobox, I let the user to select report criteria FROM xx TO xx. i have a button call btnPrint to select report criteria and print according to the criteria. I able to SELECT the...
2
1370
by: jaYPee | last post by:
i'm wondering how can i update the current record in datagrid while still editing the record. cause i have a checkbox in my datagrid and i want to save the record before changing the value of this...
3
1386
by: gmac63 | last post by:
To be brief, I have never encountered this where I make a database query: <?php $db = sqlite_open('tc.db'); $result = sqlite_query($db,"select dir,app,protocol,sport,dport,mark from...
1
2704
by: tkhouk | last post by:
I'm using Access 2003... I'm date and time stamping a record (to fields in a table) whenever it is accessed in the form and then the control is then sent back to the lookup box. While on the form,...
7
2393
by: Problematic coder | last post by:
Dim objdr As Data.OracleClient.OracleDataReader = Nothing Dim objcnn As Data.OracleClient.OracleConnection = Nothing Dim objcom As Data.OracleClient.OracleCommand objcom = New...
1
1414
by: srinivasarao yarru | last post by:
hi friends, i am getting one problem in my software can you plz try to currect that thing. In my project total 5 tables are there.from table 3 onwards i gave composite primarey key. ...
3
3455
by: mckbill | last post by:
Is there a way I can direct the cursor to a specific field (variable) in a form by typing the field name while in form view? I have a form with many fields, and it would be nice if there were...
0
2211
by: vigneshrao | last post by:
Hi, I have been working on a script that loops through multiple records and sends data (one record per call) to a WS. I am supposed to make a new call for each record before sending the data....
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.