a file problem !!

This is a discussion on a file problem !! within the C++ Programming forums, part of the General Programming Boards category; Ok well i got the function to work, the basic concept is the same there were just same design flaws ...

  1. #16
    Registered User
    Join Date
    Aug 2002
    Posts
    87
    Ok well i got the function to work, the basic concept is the same there were just same design flaws in it... i don't like it at all though, it is way to long for a function and it is messy at hell but look at the bright side, it works

    Code:
    void copy ( ifstream& input_file , ofstream& output_file )
    {
        char symbol = '\0';
        char Buffer = '\0';
    	char Buffer2 = '\0';
        
        int sum, count;
    	double average ;
    
    	input_file.get(symbol);
    
      	while ( ! input_file.eof() )
      	{
    		while ( ! isdigit(symbol) )
    	
    		{
    			output_file.put(symbol);
    			input_file.get(symbol);
    		}
    	
    		sum=0;
    		count=0;
    	
    		while(symbol != '\n' && !input_file.eof())
    		{
    			
    			if( symbol == ' ' )
    				count = count + 1;
    				
    			else if(isdigit(symbol))
    			{
    				input_file.get(Buffer);
    				
    				if(isdigit(Buffer))
    				{
    					if( symbol == '1' && Buffer == '0' )
    					{
    						input_file.get(Buffer2);
    
    						if(Buffer2 == '0')
    						{
    							sum = sum + 100;
    							output_file.put('1');
    							output_file.put('0');
    							output_file.put('0');
    						}
    						else
    						{
    							sum = sum + 10;
    							output_file.put('1');
    							output_file.put('0');
    							count = count + 1;
    						}
    					}
    					else
    					{
    						sum = sum + ( ( (int)symbol - 48 ) * 10 ) + ( (int)Buffer - 48 );
    						output_file.put(symbol);
    						output_file.put(Buffer);
    					}
    
    				}
    				
    				else
    				{
    					sum = sum + ( (int)symbol - 48 );
    					count = count + 1;
    					output_file.put(symbol);
    				}
    
    			}
    
    			else
    				break;
    
    			output_file.put(' ');
    
    			input_file.get(symbol);
    		}
    			
    			
    	
    		 
    		output_file<< "   (** sum= "<< sum << ", count: " << count ;
    	
    		output_file.setf(ios::fixed);
    		output_file.setf(ios::showpoint);
    		output_file.precision(2);
    	
    		average = (double)sum / (double)count ;
    		output_file << ", average: "<< sum << " / " << count      << " = " << average << " **) ";
    		output_file.put('\n');
    		sum = 0;
    		count = 0;
    	}
    		
    }

  2. #17
    Registered User
    Join Date
    Apr 2003
    Posts
    25
    Thank you but what is a buffer??
    have a nice day

  3. #18
    Registered User
    Join Date
    Aug 2002
    Posts
    87
    a buffer is basically something that stores something temporarily. It is probably better if you rename those varibles to soemthing a bit more clear as in this program those two variables will only hold one possible value. If you have a lot of operations that require the saving of values in the middle of it, between the original input and the final result, it is general pratice to use a temp (or as i like to call em buffer) variables.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Rename file problem
    By Emporio in forum C Programming
    Replies: 2
    Last Post: 06-05-2002, 09:36 AM

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