C Program to Compare Two Data files

C Program to Compare Two Data files

This page has a C Program to Compare Two Data files. It is clear that, this program will ask names of two existing files as input (these two data files must be created earlier either through notepad or ms-word or by any other way).Then, the program will compare the contents of the given two data files. If both files contains same contents (information), the program will display the output as the two files are Identical. If both files are having different contents, the program will display the output as the two files are not Identical. The below given C program is used to Compare Two Data files. Kindly check out the program to Compare Two Data files.

How will ask to Compare Two Data files

The questions to copy the content of one file to another file can be asked as,  1). C program to Compare any two Data files.  2). C Program to Compare two files.  3). C Program to Compare one Data file with other.  4). C Program to Compare any given two Data files.  5). C program to Compare the contents of any two Data files.  6). C program to Compare the contents of two Data files.


Program to Compare any two Data files 

  #include<stdio.h>
  int main() {
         FILE *fpointer1, *fpointer2;
         char filechar1, filechar2;
         char nam1[20], nam2[20];
         clrscr();
         printf("\n Give the first file name:");
         gets(nam1);
         printf("\n Give the second file name:");
         gets(nam2);
         fpointer1 = fopen(nam1, "r");
         fpointer2 = fopen(nam2, "r");
         if (fpointer1 == NULL)
         printf("\n The file %s has no content  to compare !", nam1);
         else if (fpointer2 == NULL)
         printf("\n The file %s has no content  to compare !", nam2);
         else
         {
          do {
          filechar1 = getc(fpointer1);
          filechar2 = getc(fpointer2);
          }while ((filechar1 != EOF) && (filechar2 != EOF) && (filechar1 == filechar2));
          if (filechar1 == filechar2)
          printf("\n The Two Files are identical");
          else if (filechar1 != filechar2)
          printf("\n The Two Files are Not identical");
          fcloseall();
          }
          getch();
          return (0);
          }


Sample Outputs:

Create two Text (data) files either using any Text editor (for example: notepad or notepad++ or Ms-word) before to run the program. If you do not create the two text files for using it in the program with 'r' mode, the program will give the output as "This file has no content to compare !! 


Related Popular Posts:

Other Related C Programs :


* C Program to find whether the given number is Odd or Even

* C Program to find the Sum of Odd Digits

* C Program to find the Sum of Even Digits

* C Program to find the Sum of Even and Odd Digits,

* C Program to Display Odd digits

* C Program to Display even digits

* C Program to Display Odd Numbers,

* C Program to Display Even Numbers,

* C Program to Check whether the given number is Armstrong number

* C Program to display the Armstrong numbers in Range

* C Program to display the Armstrong numbers between 1 and 1000

* C Program to check perfect number, perfect numbers in range

* C Program to Check Prime number, Prime numbers between 1 and 100

* C Program to display the Prime numbers in a Range

* C Program to display the Sum of Prime numbers

* C Program to Check Strong number

* C Program to display the Strong number in Range

* C Program to Check whether the given number is polindrome number or not

* C Program to Check polindrome number using for loop

* C Program to Check polindrome number using Recursion

* C Program to  check whether the given string is polindrome or not

* C Program to find the Roots of Quadratic equation

* C Program to display Fibonacci Series

* C Program to display the Fibonacci Series using an array

* C Program to display the Fibonacci Series using while loop

* C Program to find the Sum of Fibonacci Series, Factorial of Number

* C Program to find the Factorial without using Recursion

* C Program to find the Factorial using Pointers

* C Program to find the Factorial using Function

Bookmark and Share