Help with loading data.

This is a discussion on Help with loading data. within the C++ Programming forums, part of the General Programming Boards category; ***Warning this is for homework. I am on the final debug for a program of mine. The program is designed ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    11

    Help with loading data.

    ***Warning this is for homework.

    I am on the final debug for a program of mine. The program is designed to restart your computer upon going beyond the boundaries of your stack. The stack is an array based stack. When it restarts, the program saves the information in the stack to a file and when the computer starts again, it loads the data back into the stack.

    The problem I am having is that although it saves the data, when it loads, the data is only a series of zeros. I thought of using ios::nocreate, but my program won't let me use it, saying that its invalid. The appropriate code follows.

    Section to place data back into stack:
    Code:
    int j = 0;
    
    ifstream CrashRecover;
    ofstream Coredump1;
    
    CrashRecover.open("C:\\coreDump.dat");
    Coredump1.open("C:\\coreDump.dat");
    
    if(!CrashRecover)
    {
                   cout<<"Welcome to the stack   
                      manipulator."<<endl;
                   cout<<"Please enjoy yourself."<<endl;
    }
    else
    {
    	int loop = 5;
    	cout<<"Now Recovering from Stack 
                         Overflow and System Crash....."<<endl;
    	Stackmanip.initialize();
    	CrashRecover>>j;
    	while(loop != 0)
                    {
    	         Stackmanip.push(j);
    	         CrashRecover>>j;
    	         loop--;
                     }
    	cout<<"Now don't do it again Hoser!!!"<<endl;
    Section to initiate restart error:
    Code:
    if(Stackmanip.isItFull() == true)
    {
    	cout<<"Warning!!!  Warning!!Warning!"<<endl;
    	cout<<"Stack Overflow."<<endl;
    	while(!Stackmanip.isItEmpty())
    	{
    		Stackmanip.popIt(popWhat);
    		Coredump1<<popWhat<<endl;
    	}
    	Coredump1<<endl;
    	system("copy A:project3.exe c:\\");
    	Stackmanip.restart();
    }
    I have included the right header files. <cstdlib> <fstream>

    Thank you all.

  2. #2
    Epo
    Epo is offline
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    Just a question. Is this how the process works?...
    1) You run out of stack memory
    2) All that information is stored in a text file
    3) Your computer restarts
    4) All that information stored in a text file is brought back into the stack
    5) You run out of stack memory
    6) ...

    And now for something useful perhaps, could there be a problem with having the same file open twice at the same time for I/O?
    CrashRecover.open("C:\\coreDump.dat");
    Coredump1.open("C:\\coreDump.dat");

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    11
    Yes to the first, and there shouldn't be a problem with using the same file for both variables. One is an input variable the other output. please inform me if I am wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 04:45 AM
  2. dynamically loading data?
    By elninio in forum C++ Programming
    Replies: 15
    Last Post: 07-28-2008, 01:46 AM
  3. Binary Tree, couple questions
    By scoobasean in forum C Programming
    Replies: 3
    Last Post: 03-12-2005, 09:09 PM
  4. C Programming Question
    By TK in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 07-04-2002, 08:11 PM
  5. Loading a struct with data from a file
    By TankCDR in forum C Programming
    Replies: 1
    Last Post: 10-28-2001, 08:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21