Thread: input out file linklists

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    4

    input out file linklists

    can anybody help me get a input file to input number data one line at a time and then output it to a output file. it reads the data but does not stop and move to another line. I need the data to stop after the first full line and then start on the second.

    Code:
    int main()
    {
    
    
    	/******************************************************************************
    
      outputs the file
      ************************************************************************/
    	ifstream fin;
    	ofstream fout;
    
    	/*********************************************************************
    	gives the array a variable name
    	******************************************************************/
    
    	lref head;
    
    	head = NULL;
    
    	lref end;
    
    	lref tail;
    
    	end = new Node;
    
    	if (head == NULL)
    	{
    		head = end;
    
    	}
    
    	else
    	{
    		tail= end;
    
    		end->next = new Node;
    	}
    
    
    
    	   
    
    	fin.open("input.txt");  //opens the input file
    
    	if (fin.fail())
    	{
    
    		cout <<"Input file failed." << endl;
    
    			exit(1);
    	}
    
    	fout.open("outs.txt");  //opens the output file
    
    	if (fout.fail())  //  will output a error if the output file fails
    	{
    		cout << "Output file failed." << endl;
    
    		exit(1);
    
    	}
    
    	/**********************************************************
    	gives the decimal point and sets it to 2
    	******************************************************/
    
    	fout.setf(ios::fixed);
    
    	fout.setf(ios::showpoint);
    
    	fout.precision(2);
    
    	/***********************************************************
    	outputs the average and total info to the output file for display
    	**************************************************************/
    
    
    	fout << "January" <<setw(15) << "February" << setw(15) << "March" << setw(15) << "Average" << endl;
    
    	do
    	{
    		
    		TotalSales sum(lref& head);
    
    		
    
    		fin >> head->data;
    
    		
    
    		fout <<head->data << setw(15);		
    
    	}
    
    	
    
    while (! fin.eof());
    	
    
    
    
    	fin.close();
    	fout.close();  //closes the output file
    
    	delete head, end, tail;
    
    	system("pause"); // pauses the screen after the program runs
    
    	return 0;
    
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> TotalSales sum(lref& head);

    I'm not sure I understand your problem, but the line of code above does nothing, it just declares a function but doesn't call it. Maybe you were expecting that code to be called?

    >> delete head, end, tail;

    Also, that line is wrong, you must call delete on each of those separately if they all need to be deleted.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 04:49 PM
  4. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM