VOOZH about

URL: https://www.geeksforgeeks.org/c/c-program-compare-two-files-report-mismatches/

⇱ C program to compare two files and report mismatches - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C program to compare two files and report mismatches

Last Updated : 23 Jul, 2025
We are given almost two identical files. But some characters are corrupted. We need to find the line number and their position where those corrupted letter exists as well as Total number of corrupted (error) letters. Examples:
Input :
file1.txt contains
it is
fun
file2.txt contains
it is
run

Output :
Line Number : 2 Error Position : 1
Total Errors : 1
Prerequisite : getc() in C Steps : 1.> Open two file using File pointer in read only mode. 2.> Fetch data of file in two char variable one by one until end of file. 3.> If variable encounter new line then increment line number and reset position to zero. 4.> If variables are not equal then increment number of error and print error line as well as error index. Output:
Line Number : 2 Error Position : 1
Total Errors : 1

Comment
Article Tags: