
Printf("Line: %d, col: %d\n", line, col) Printf("Please check whether file exists and you have read privilege.\n") ĭiff = compareFile(fPtr1, fPtr2, &line, &col) * fopen() return NULL if unable to open file in given mode. * File pointer to hold reference of input file */ Int compareFile(FILE * fPtr1, FILE * fPtr2, int * line, int * col) * C program to compare two files character by character.
If both files has reached end then return 0 otherwise return -1. Repeat step 5-6 until characters from both files are matching, or file has reached end. Otherwise, increment *col by one if both characters are same. If both characters are different then return -1. Increment *line by one and set *col = 0 if current character is new line character '\n'. Read a character from both files and compare. The function will return 0 if both files are same, otherwise returns -1. Define a function int compareFile(FILE * fPtr1, FILE * fPtr2, int * line, int * col). Open both files in r (read) mode and store their references in fPtr1 and fPtr2.
Input file path of two files to compare from user, store it in path1 and path2.
Step by step descriptive logic to compare two files character by character. File 1 Learn C programming at Codeforwin.įile 2 Learn C programming at Codeforwin.īasic Input Output, Pointers, String, File Handling, Logic to compare two files