GNU   davin.50webs.com/research
Bringing to you notes for the ages

       Main Menu          Research Projects         Photo Album            Curriculum Vitae      The Greatest Artists
    Email Address       Computer Games          Web Design          Java Training Wheels      The Fly (A Story)   
  Political Activism   Scruff the Cat       My Life Story          Smoking Cessation          Other Links      
Debugging Macros     String Class I     Linked List System I Java for C Programmers Naming Convention
    String Class II         How I use m4              Strings III                 Symmetrical I/O             Linked Lists II     
Run-Time Type Info   Virtual Methods      An Array System        Science & Religion            Submodes       
  Nested Packages      Memory Leaks    Garbage Collection      Internet & Poverty      What is Knowledge?
Limits of Evolution   Emacs Additions      Function Plotter           Romantic Love        The Next Big Thing
    Science Fiction     Faster Compilation Theory of Morality         Elisp Scoping               Elisp Advice      
  S.O.G.M. Pattern       Safe Properties         School Bullying          Charisma Control          Life and Death    
     Splitting Java          Multiple Ctors       Religious Beliefs         Conversation 1           Conversation 2    
   J.T.W. Language    Emacs Additions II      Build Counter             Relation Plotter          Lisp++ Language  
  Memory Leaks II   Super Constructors CRUD Implementation Order a Website Form There Is An Afterlife
More Occam's Razor C to Java Translator Theory of Morality II


compare-files.cc

    
#include <stdio.h>
#include <stdlib.h>

#define null (0)

int main(int argc, char** argv)
{
   if (argc != 3)
   {
      printf("Usage: compare-files.exe FILENAME1 FILENAME2\n");
      exit(EXIT_FAILURE);
   }

const char* FILENAME1 = argv[1];
   const char* FILENAME2 = argv[2];

bool error1 = false;
   bool error2 = false;

FILE* f1 = fopen(FILENAME1, "rb");
   if (f1 == null)
   {
      error1 = true;
   }

FILE* f2 = fopen(FILENAME2, "rb");
   if (f2 == null)
   {
      error2 = true;
   }

if (error1 && error2)
   {
      printf("RESULT=NO Error opening files \"%s\" and \"%s\" for reading\n", FILENAME1, FILENAME2);
      exit(EXIT_FAILURE);
   }
   if (error1)
   {
      printf("RESULT=NO Error opening file \"%s\" for reading\n", FILENAME1);
      exit(EXIT_FAILURE);
   }
   if (error2)
   {
      printf("RESULT=NO Error opening file \"%s\" for reading\n", FILENAME2);
      exit(EXIT_FAILURE);
   }

   //std::cout << "EOF=" << EOF << '\n';

   int count = 0;
   for (;;)
   {
      int ch1 = fgetc(f1);
      int ch2 = fgetc(f2);
      count++;
      if ((ch1 == EOF) && (ch2 == EOF))
      {
         printf("RESULT=YES\n");
         exit(EXIT_SUCCESS);
      }
      else if ((ch1 == EOF) || (ch2 == EOF))
      {
         printf("RESULT=NO Files are of different lengths at position %d\n", count);
         exit(EXIT_FAILURE);
      }
      else if (ch1 != ch2)
      {
         printf("RESULT=NO Files different at position %d\n", count);
         exit(EXIT_FAILURE);
      }
   }
}
Back
| Main Menu | Research Projects | Photo Album | Curriculum Vitae | The Greatest Artists |
| Email Address | Computer Games | Web Design | Java Training Wheels | The Fly (A Story) |
| Political Activism | Scruff the Cat | My Life Story | Smoking Cessation | Other Links |
| Debugging Macros | String Class I | Linked List System I | Java for C Programmers | Naming Convention |
| String Class II | How I use m4 | Strings III | Symmetrical I/O | Linked Lists II |
| Run-Time Type Info | Virtual Methods | An Array System | Science & Religion | Submodes |
| Nested Packages | Memory Leaks | Garbage Collection | Internet & Poverty | What is Knowledge? |
| Limits of Evolution | Emacs Additions | Function Plotter | Romantic Love | The Next Big Thing |
| Science Fiction | Faster Compilation | Theory of Morality | Elisp Scoping | Elisp Advice |
| S.O.G.M. Pattern | Safe Properties | School Bullying | Charisma Control | Life and Death |
| Splitting Java | Multiple Ctors | Religious Beliefs | Conversation 1 | Conversation 2 |
| J.T.W. Language | Emacs Additions II | Build Counter | Relation Plotter | Lisp++ Language |
| Memory Leaks II | Super Constructors | CRUD Implementation | Order a Website Form | There Is An Afterlife |
| More Occam's Razor | C to Java Translator | Theory of Morality II
Last modified: Sat Oct 29 20:43:27 NZDT 2016
Best viewed at 800x600 or above resolution.
© Copyright 1999-2016 Davin Pearson.
Please report any broken links to