codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  small question  The_Master at 13:58 on Tuesday, December 19, 2006
 

Could any one tell me what does the lined code in the last mean?

[CODE]#include <iostream>
#include <fstream>
using namespace std;
bool differsByOneDigit ( int , int );
void outputResults ( ostream & , const int * , int , bool );

int main()
{

ifstream input ( "/forum/cdata.txt" );
ofstream output ( "/forum/cout.txt" );

if ( input.fail() || output.fail() )
{
cout <<"input or output file did not open!!! " << endl;
return 1;
}
int first , next ; //32bit int == 2147483647
int sequence [ 10 ];//sequence read
int seqLength = 0; //sequence length
int j;
int temp;
bool match; //matching sequence
int firstSeq;

if ( ! ( input >> temp ) )
{
//until you here otherwise, bad file format will be handled by program termination.
cout << "File has a non-int within" << endl;
cout << "Bad file format , terminating program!!! "<< endl ;
return 1;
}
else if ( (temp > 1000000000) || (temp < -1 ) )
{
//until you here otherwise, out of range number will be handled by program termination
cout << "File has out of range number "<< endl;
cout << " TERMINATING program!!! "<< endl;
return 1;
}
while (input)
{
firstSeq = temp;
//read next sequence
while ( temp != -1 && seqLength < 10 && !input.eof() )
{
sequence [ seqLength ++ ] = temp;
if ( ! ( input >> temp ) )
{
//until you here otherwise, bad file format will be handled by program termination.
cout << "File has a non-int within"<< endl;
cout << "Bad file format , terminating program!!! "<< endl ;
return 1;
}
else if ( (temp > 1000000000) || (temp < -1 ) )
{
//until you here otherwise, out of range number will be handled by program termination
cout << "File has out of range number "<< endl;
cout << " TERMINATING program!!! " << endl;
return 1;
}
}
if ( temp != -1 )
{
//until you here otherwise, bad file format will be handled by program termination.
cout << "File has a sequence length greater than 10!!!"<< endl;
cout << "Bad file format , terminating program!!! "<< endl;
return 1;
}
if ( seqLength <= 1 )
{

cout << "Sequence of one or less found!!"<< endl ;
cout << "Bad file format , terminating program!!! " << endl;
return 0;

}
sequence [ seqLength ] = -1;
j = 0;
first = sequence [ j ];
next = sequence [ j + 1 ];
j += 2;
match = true;
while ( match && next != -1)
{
match = differsByOneDigit( first , next );
first = next;
next = sequence [ j ];
j++;
}
if ( match )
match = differsByOneDigit ( first , firstSeq ); //check front to back
outputResults ( output , sequence , seqLength , match );
if ( ! ( input >> temp ) )
{
if ( !input.eof() )
{
//until you here otherwise, bad file format will be handled by program termination.
cout << "File has a non-int within"<< endl ;
cout << "Bad file format , terminating program!!! "<< endl;
return 1;
}
}
else if ( (temp > 1000000000) || (temp < -1 ) )
{
//until you here otherwise, out of range number will be handled by program termination
cout << "File has out of range number "<< endl ;
cout << "TERMINATING program!!! "<< endl;
return 1;
}
seqLength = 0;
}
output.close();
input.close();
return 0;
}
bool differsByOneDigit ( int first , int next )
{
int differentDigits = 0;
while ( first != 0 && next != 0 && differentDigits <= 1 )
{
if ( first % 10 != next % 10 ) //count different digits
differentDigits ++;
first /= 10;
next /= 10;
}
if ( differentDigits > 1 || first || next )
return false;
else
return true;
}
void outputResults ( ostream & output , const int * sequence , int length , bool isChainedSequence )
{
int j = 0;
output << "The sequence : ";
cout << "The sequence : ";
while ( j < length && sequence [ j ] != -1 )
{
output << sequence [ j ] << " " ;
cout << sequence [ j ++ ] << " " ;
if ( j % 7 == 0 )
{
output << endl;
cout << endl;
}
}
if ( isChainedSequence )
{
output << " is chained. " << endl;
cout << endl << "has been found....OPEN the output file to CHECK whether is it chained or not" << endl;
}
else
{
output << " is not chained. " << endl;
cout << endl << "has been found....OPEN the output file to CHECK whether is it chained or not" << endl;
}
output << endl <<"****************************************************" << endl;
cout << endl <<"****************************************************" << endl;
}[CODE]








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  I need your help_ My last exam..help..help.. me...
•  Re: What is This?
•  logging console output of stored procedure to file
•  Re: need help!!!
•  Connecting to an https server using NNTP perl
•  Is there an ADMIN!!!!! Is this place maintained!
•  small question
•  Re: Text to Speech Converter
•  Re: Multithreading question


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2006