On Wed, 23 Apr 2008 05:26:32 +0000, Richard Heathfield wrote:
Right. So that's a simple check to add, after the loop. If you've run out
of first file, you try to read a line from the second file. If that
doesn't work either because you've run out of file, then the files match..
Otherwise, they don't, and the second file is longer.
OK, I am able to run it successfully
. it is messiest code I ever wrote
void compare_files( FILE* pf1, FILE* pf2 )
{
char line1[ARRSIZE];
char line2[ARRSIZE];
const char *begin_line1, *begin_line2, *p1, *p2;
int files_equal, file1, file2, eof_file1, eof_file2;
files_equal = 1;
file1 = 1;
file2 = 1;
eof_file1 = 0;
eof_file2 = 0;
while( files_equal && file1 && file2 )
{
begin_line1 = p1 = fgets( line1, ARRSIZE, pf1 );
begin_line2 = p2 = fgets( line2, ARRSIZE, pf2 );
if( !p1 && !p2 )
{
file1 = file2 = 0;
}
else if( (!p1 && p2) )
{
files_equal = 0;
eof_file1 = 1;
}
else if( !p2 && p1 )
{
files_equal = 0;
eof_file2 = 1;
}
else if( strcmp( p1, p2 ) )
{
files_equal = 0;
eof_file1 = eof_file2 = 1;
}
}
if( !files_equal )
{
if( eof_file1 )
{
puts(begin_line2);
}
else if( eof_file2 )
{
puts(begin_line1);
}
else if( eof_file1 && eof_file2 )
{
puts( begin_line1 );
printf("\n-------------------------\n");
puts( begin_line2 );
}
}
--http://lispmachine.wordpress.com/
my email ID is at the above address