Hello, all:
I am getting strange results when debugging this code:
(The logic of the code is wrong because I am just modifying it)
while(projTable->readNextRecord(projTable) != EOF)
{
int thisProjectID = atoi(projTable->readField(projTable, proj_id));
if (projectID_ == 0)
{
projectID_ == thisProjectID;
break;
}
if (thisProjectID == projectID_)
break;
}
if (projectID_ == 0)
return setErrStatus(projectNotFound);
At the beginning, projectID_ is zero. When the program reaches the first if (if (projectID_ == 0))
it jumps out of the loop to the line with the return.
A new version of the code:
bool found = false;
int thisProjectID = 0;
while(!found && projTable->readNextRecord(projTable) != EOF)
{
thisProjectID = atoi(projTable->readField(projTable, proj_id));
if (projectID_ == 0)
{
projectID_ == thisProjectID;
found = true;
break;
}
if (thisProjectID == projectID_)
{
found = true;
break;
}
}
if (! found)
if (projectID_ == 0)
In this case, from the first if, it jumps inside the second if (if (thisProjectID == projectID_)), to the break statement.
My final working version is this (it works ok):
bool found = false;
int thisProjectID = 0;
while(!found && projTable->readNextRecord(projTable) != EOF)
{
thisProjectID = atoi(projTable->readField(projTable, proj_id));
if (projectID_ == 0)
found = true;
else
found = thisProjectID == projectID_;
}
if (!found)
return setErrStatus(projectNotFound);
Can anybody find an explanation of this behavior?
This is so simple that I am sure I screwed it somewhere.
It looks like the program does not execute what the source code says.
Thank you for your time,
Simon