J
jbruno4000
I'm having 2 problems and hope you can help:
Fist Problem: Please see the code segment bellow. For this application I need
to access an input file and also an output file, however, when I include the
statements to access to access the output file, I get an access violation
error. When I comment out the output file statements, the program runs fine.
Code segment:
int main()
{
int choice = 1; // To store menu option selected by user
ifstream infile; // input file access
// ofstream outfile;
char* inputFile; // input file
char* outputFile; // outputFile
NodePtr head; // External pointer to head of linked
list
NodePtr currPtr; // Points to current node
NodePtr newNodePtr; // points to newest node
char noun[30], partNum[20], locationID[10]; // temp storage for file
input data
int qtyInStock, restockL; // " " "
inputFile = "mystock.txt";
outputFile = "update.txt";
infile.open(inputFile);
if(!infile)
{
cout << "Could not open file: " << inputFile << endl;
return 1;
}
// outfile.open(outputFile);
// if(!outfile)
// {
// cout << "Could not open file: " << outputFile << endl;
// return 1;
// }
SecondProblem : In reading from the intput file, I simply want to say:
infile >> data;
while(infile)
{
......
.......
infile >> next data;
}
When I do it this way, I get stuck in an infinite loop. It reads all the data
in the file but instead of exiting the loop, it continues to input the last
line indefinitely. To overcome the problem I've had to enter a '-1' for two
integer data items on the last line of the file and use that as the test for
end of file. I need to be able to do it the right way, so please help! Here's
the code segment:
infile >> noun >> partNum >> locationID >> qtyInStock >> restockL;
while((restockL != -1) && (qtyInStock != -1))
{
newNodePtr = new SupplyItem;
strcpy(newNodePtr->nomenclature, noun);
strcpy(newNodePtr->partNumber, partNum);
strcpy(newNodePtr->locID,locationID);
newNodePtr->quantityInStock = qtyInStock;
newNodePtr->restockLevel = restockL;
currPtr->link = newNodePtr;
currPtr = newNodePtr;
infile >> noun >> partNum >> locationID >> qtyInStock >> restockL;
}
currPtr->link = NULL;
Thanks for taking the time.
Josh
Fist Problem: Please see the code segment bellow. For this application I need
to access an input file and also an output file, however, when I include the
statements to access to access the output file, I get an access violation
error. When I comment out the output file statements, the program runs fine.
Code segment:
int main()
{
int choice = 1; // To store menu option selected by user
ifstream infile; // input file access
// ofstream outfile;
char* inputFile; // input file
char* outputFile; // outputFile
NodePtr head; // External pointer to head of linked
list
NodePtr currPtr; // Points to current node
NodePtr newNodePtr; // points to newest node
char noun[30], partNum[20], locationID[10]; // temp storage for file
input data
int qtyInStock, restockL; // " " "
inputFile = "mystock.txt";
outputFile = "update.txt";
infile.open(inputFile);
if(!infile)
{
cout << "Could not open file: " << inputFile << endl;
return 1;
}
// outfile.open(outputFile);
// if(!outfile)
// {
// cout << "Could not open file: " << outputFile << endl;
// return 1;
// }
SecondProblem : In reading from the intput file, I simply want to say:
infile >> data;
while(infile)
{
......
.......
infile >> next data;
}
When I do it this way, I get stuck in an infinite loop. It reads all the data
in the file but instead of exiting the loop, it continues to input the last
line indefinitely. To overcome the problem I've had to enter a '-1' for two
integer data items on the last line of the file and use that as the test for
end of file. I need to be able to do it the right way, so please help! Here's
the code segment:
infile >> noun >> partNum >> locationID >> qtyInStock >> restockL;
while((restockL != -1) && (qtyInStock != -1))
{
newNodePtr = new SupplyItem;
strcpy(newNodePtr->nomenclature, noun);
strcpy(newNodePtr->partNumber, partNum);
strcpy(newNodePtr->locID,locationID);
newNodePtr->quantityInStock = qtyInStock;
newNodePtr->restockLevel = restockL;
currPtr->link = newNodePtr;
currPtr = newNodePtr;
infile >> noun >> partNum >> locationID >> qtyInStock >> restockL;
}
currPtr->link = NULL;
Thanks for taking the time.
Josh